Solved

Case sensitivity difference between .NET 2.0 and 4.0

Posted on 2013-11-19
6
332 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 63

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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 63

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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
"Emulate" TAB key when press Enter Key 3 72
Code enhancement 4 33
Add Combobox column to datagridview using vb.net 2 27
Need help with another query 10 38
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

733 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