Solved

Case sensitivity difference between .NET 2.0 and 4.0

Posted on 2013-11-19
6
334 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
[X]
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
  • 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
Independent Software Vendors: 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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

728 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