Solved

Case sensitivity difference between .NET 2.0 and 4.0

Posted on 2013-11-19
6
323 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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

758 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

18 Experts available now in Live!

Get 1:1 Help Now