Solved

Case sensitivity difference between .NET 2.0 and 4.0

Posted on 2013-11-19
6
324 Views
Last Modified: 2013-11-20
x = "Test"
If x = "test"
    do abc
Else
    do efg
End if

I have proven the above code works differently between my .NET 2.0 and .NET 4.0 console apps.
.NET 2.0 console app will execute abc.  
.NET 4.0 console app will execute efg.

Why doesn't the 2.0 app do the same thing as the 4.0 app?  Is there a configuration that says to not worry about case sensitivity or something?
0
Comment
Question by:ToolTimeGang
  • 3
  • 2
6 Comments
 
LVL 62

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 39660192
Hi ToolTimeGang;

By default string compare are case sensitive unless it has been change to case insensitive. This is done by setting the following statement at the top of the code file:

' Case insensitive compare
Option Compare Text

' Case sensitive compare
Option Compare Binary

If the above is not in the file at the top then in the project configuration on the Compile tab the Option compare Combobox is set to Text

Please check your setting as stated above.
0
 

Author Comment

by:ToolTimeGang
ID: 39660207
Bingo.  The 2.0 app had Option Compare = Text instead of binary.
I changed it, and the code is executing like the 4.0 code.
thanks for your prompt response!
0
 

Author Closing Comment

by:ToolTimeGang
ID: 39660210
You rock for getting back to me so quickly.  This was driving me nuts!  Thank you!
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 62

Expert Comment

by:Fernando Soto
ID: 39660213
Not a problem ToolTimeGang, glad I was able to help. Have a great day.
0
 
LVL 40
ID: 39661642
Actually, although it solved your problem, the information given by Fernando is not quite complete.

Option Compare Binary compare the binary values of the characters, their Unicode value, which makes it both Case and accent sensitive. The results are thus the same no matter the system on which it runs.

Option Compare Text follows the language specified in the Control Panel, and will thus change depending on the language. Most languages are case insensitive, but many are sensitive to accents. The results might thus be different from one computer to another.

The best way to compare strings is to use the String.Compare method. It has overloads that let you specify the case sensitivity and the language to use for everything else, so it is the only way to be assured of always getting the same results in a given application.
0
 

Author Comment

by:ToolTimeGang
ID: 39662489
Awesome.  That is exactly what I ended up coding yesterday:

...If String.Compare(msgType, "event", True) = 0 Then...

Thank you so much for taking the time to make that point even after the entry was closed.  That shows you care.  Have a great Thanksgiving!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

911 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now