|
-
Jan 21st, 2010, 04:32 AM
#1
Thread Starter
Fanatic Member
Comparing String,
Below two which is the best practise to compare strings...
Code:
If "A".ToLower = "a" Then
'....
End If
If String.Compare("A", "A", True) = 0 Then
'...
End If
Visual Studio.net 2010
If this post is useful, rate it

-
Jan 21st, 2010, 06:04 AM
#2
Re: Comparing String,
The first example you provided isn't a true comparison as for example you are changing what the user entered into a lowercase; no longer representing what was entered. A true comparison would be does "A" = "A". So based on that the second example would have to win as it is a comparison IMHO.
-
Jan 21st, 2010, 07:12 AM
#3
Hyperactive Member
Re: Comparing String,
I always use String.Equals as it returns a boolean and you do not have to compare to 0. Additionalty you can define how to compare the values.
Code:
If String.Equals("A", "a", StringComparison.OrdinalIgnoreCase) Then
...
End If
To deny our own impulses is to deny the very thing that makes us human
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|