Jump to content
xisto Community
Sign in to follow this  
karl77

What If You Want To Compare Case Sensitive Strings?

Recommended Posts

The usual way to do this in VB.NET is:

Code:

if StrComp(String1,String2,vbTextCompare)=0 then    'same stringsend if
But the improvements of .Net, and the last recommandations imply that all should be methods/attributes:

Code:
If String.Compare(String1,String2,True)=0 then    'same stringsend if

You can also use the method:

Code:
if String1.CompareTo(String2,True)=0 then    'same stringsend if

Share this post


Link to post
Share on other sites

Hi!You could also use the Equals method as the String class overrides the Equals method of the Object class to perform a case-sensitive matching check. This is used as follows:if (str1.Equals(str2)) { //the strings are the same}The "==" operator can also be used for most checks as the framework performs string interning.CompareTo is useful for sorting - it can tell you if a string is greater than or less than another based on precendence in the alphabet.Regards,Nitin Reddy

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.