I want to compare a string item in a collection with another string variable. I use collection.items.contains(string_var) to compare if the string_var is in the collection. But i need to compare case insensitive !! How can i do this ?
Printable View
I want to compare a string item in a collection with another string variable. I use collection.items.contains(string_var) to compare if the string_var is in the collection. But i need to compare case insensitive !! How can i do this ?
Can you post some more code?
Anyway what kind of objects are in the collection? You can use a for each loop and compare.
Did you try that?
The collection contains only string items. I know that i can use a for each loop, but is there no other way ?. As long as i have the items.contains function in a collection i really would like to use it.
Example:
VB Code:
dim coll as new collection coll.items.add("Part1") coll.items.add("PaRt2") coll.items.add("pArt3") dim something as string = "part2" if coll.items.contains(something) then messagebox.show("Found it")
I hope this helps
I dont know what else to tell you, but if that is not working use the for each loop instead.
In the for each loop you can assign a string variable each string in the collection, convert it to upper or lower case, convert the variable you are comparing then compare the results.
Hope that helped.
I know that, but i am trying to find a more elegant way.Quote:
Originally posted by DevGrp
In the for each loop you can assign a string variable each string in the collection, convert it to upper or lower case, convert the variable you are comparing then compare the results.
Hope that helped.
the compare method of the string object takes 3 parameters the first 2 are strings to compare, and the third is a boolean to see if you want to ignore case. It returns an integer that I guess represents if they match or not. Try using that.