dim al as new arraylist
al.add("one")
al.add("two")
dim x as integer = al.indexof("ONE") I would like this to find the match
and return 0
Is there a way to make this happen?
John
example:
dim al as new arraylist
al.add("one")
al.add("two")
dim x as integer = al.indexof(lcase("ONE"))
but in this case, if you have al.add("oNe") then i guess it wont work.
you could always do al.add(lcase("oNe")).
or you could use this simple search pattern instead to overcome that
problem. hopefully your arraylist isnt too big, otherwise this would
take a while.
Public al As Collections.ArrayList
Private obj As Object
Private strtest As String
Private indexof As Integer
Public Sub mysub()
al.Add("hello")
strtest = "HeLLo"
For Each obj In al
If LCase(CStr(al.Item(al.IndexOf(obj)))) = LCase(strtest) Then
indexof = al.IndexOf(obj)
End If
Next
End Sub
Please dont hit me if it doesnt work. i havnt tested it!
Hope this helps. Matt
after the line: indexof = al.IndexOf(obj)
you will to put: exit for
Hth Greetz Peter
Dim arrList As New ArrayList
arrList.Add("One")
arrList.Add("tWo")
arrList.Add("thRee")
arrList.Sort(CaseInsensitiveComparer.Default)
MsgBox(arrList.BinarySearch("three",
CaseInsensitiveComparer.Default))
--
Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to produce
bigger and better idiots. So far, the Universe is winning.
"Matt" <mat...@interactiveideasandsolutions.com> schreef in bericht
news:OvgG37hz...@TK2MSFTNGP12.phx.gbl...
In addition to Peters comments. Option compare text will make all
of your string compares case insensitive.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vblr7/html/vastmOptionCompare.asp
Ken
---------------
"Matt" <mat...@interactiveideasandsolutions.com> wrote in message
news:OvgG37hz...@TK2MSFTNGP12.phx.gbl...
John
"Peter Proost" <ppr...@nospam.hotmail.com> wrote in message
news:%23Dg%23dyizF...@TK2MSFTNGP09.phx.gbl...
I tried option Compare but it didn't work for the IndexOf which gets
evaluated in the object.equals method.
Ron
"Ken Tucker [MVP]" <vb...@bellsouth.net> wrote in message
news:%23IQgUDl...@TK2MSFTNGP12.phx.gbl...
Thanks Peter
"If comparer is provided, the elements of the ArrayList are compared to the
specified value using the specified IComparer implementation. If the
ArrayList is not already sorted according to the sort order defined by
comparer, the result might be incorrect."
you can try it for yourself, if you remove the
arrList.Sort(CaseInsensitiveComparer.Default) from my small example you
should get the wrong result.
Hth Greetz Peter
--
Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to produce
bigger and better idiots. So far, the Universe is winning.
"Dennis" <Den...@discussions.microsoft.com> schreef in bericht
news:D891F9E9-68B4-41CB...@microsoft.com...
The reason ArrayList.BinarySearch is only defined on sorted lists is because
the Binary Search algorithm is "optimally" defined on sorted lists.
For details on the Binary Search algorithm see:
http://www.nist.gov/dads/HTML/binarySearch.html
http://en.wikipedia.org/wiki/Binary_search
--
Hope this helps
Jay
T.S. Bradley - http://www.tsbradley.net
"Dennis" <Den...@discussions.microsoft.com> wrote in message
news:D891F9E9-68B4-41CB...@microsoft.com...