Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

operator question

Posted on 2004-04-08
5
232 Views
Last Modified: 2010-04-15
here is the code:

if ((sFileExtension != ".doc") || (sFileExtension != ".txt"))
{

}

im looking to see if uploaded file is either .doc OR .txt


the above doesnt work. how come?

0
Comment
Question by:tmueller18
  • 4
5 Comments
 
LVL 5

Accepted Solution

by:
millsoft earned 250 total points
ID: 10784768
Hi tmueller18,

Your boolean operators are wrong.

if ((sFileExtension == ".doc") || (sFileExtension == ".txt"))
{
    // extension is .DOC or .TXT
}
else
{
    // it is not
}

Cheers!
Brad
0
 
LVL 5

Expert Comment

by:millsoft
ID: 10784784
!= is "NOT EQUALS"
== is "EQUALS"

You were checking to see if the extension is "NOT .DOC or NOT .TXT".  One of those conditions will ALWAYS be true.
0
 
LVL 5

Expert Comment

by:millsoft
ID: 10784791
>One of those conditions will ALWAYS be true.

because it cannot be both at the same time.
0
 

Author Comment

by:tmueller18
ID: 10784795
thanks!
0
 
LVL 5

Expert Comment

by:millsoft
ID: 10784813
happy to help
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
What is "public object" in C#? 3 63
Question! 4 38
C# bracket error 3 35
Sort GridView by ID Descending 1 17
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

789 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question