|
-
Aug 14th, 2002, 05:18 PM
#1
Thread Starter
Member
compare a item in a collection
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 ?
-
Aug 14th, 2002, 07:47 PM
#2
Frenzied Member
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?
Dont gain the world and lose your soul
-
Aug 15th, 2002, 07:16 AM
#3
Thread Starter
Member
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
-
Aug 15th, 2002, 10:43 AM
#4
Frenzied Member
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.
Dont gain the world and lose your soul
-
Aug 15th, 2002, 11:52 AM
#5
Thread Starter
Member
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.
I know that, but i am trying to find a more elegant way.
-
Aug 15th, 2002, 12:13 PM
#6
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.
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
|