Thursday, December 01, 2005

.NET: String Comparisons

typically most developers compare strings in a case instensitive way like this:

if var.toLower = "expected" then
...
end if

this way is a little inneficient and does not take into account cultural differnces (some languages use groups of letters to signify one letter, some letters follow uppercase / lowercase rules differently).

for comparisons I use this everywhere now:

If String.Compare(var, "expected", True) = 0 Then
...
end if

I wish it would return a boolean though.
it returns less than 0 is var is less than expected
0 if they are equal
greater than 0 if expected is greater than var

0 Comments:

Post a Comment

<< Home