0

i have a list of large number of string elements in array and i am using contains function to check if it contains that element. it is working fine. Now i want to get to know the index/position of element. suppose the array is

dim s as string() = {"first", "second","third"}

and the string

dim l as string = "third"

method

dim b as boolean = s.Contains(l, StringComparer.CurrentCultureIgnoreCase)

flag

if (b) Then
messagebox.show("It exists") 
end if

above array is just an example. original array consists of 7690 entries and each entry is written in utf-8 and indexOf function is not giving any result

1
  • If the array does contains your string, it also should be able to give you the string's index. Commented Apr 6, 2015 at 12:12

2 Answers 2

0

First of all, you should consider using a List(Of T) when writing in VB.Net.

The List class provides an List(Of T).IndexOf Method (T).

You can do something like this :

Dim index As Integer = YourList.IndexOf(l)
Sign up to request clarification or add additional context in comments.

Comments

0

I believe you're looking for the IndexOf function.

UPDATE: I came up with the following quick example that encoded a string similar to your example string into UTF-8 and it still works:

    Dim s As String() = {"first", "second", "third", "four", "five", "six"}

    For Each tempString As String In s
        Dim bytes As Byte() = Encoding.Default.GetBytes(tempString)
        tempString = Encoding.UTF8.GetString(bytes)
    Next

    Dim l As String = "six"
    Debug.Print(Array.IndexOf(s, l))

1 Comment

sort of. indexOf function doesn't work. I am currently working with a array of 7690 entries and each entry/string is in utf-8 format

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.