Help with Array.FindIndex

Help with Array.FindIndex

xenocatalyst
Advocate Advocate
226 Views
3 Replies
Message 1 of 4

Help with Array.FindIndex

xenocatalyst
Advocate
Advocate

Hi,

 

I would like to use the FindIndex function of Array but I cant seem to get it to work.

My array is a string array, I don't know if this is a problem.

I have tried numerous iterations but have not had any success.

 

Could someone please help me to get this working, or confirm if this can work with a string array?

 

Here is my basic non functioning test code:

Dim oTest As String = "D"
Dim oList() As String = {"0", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" } 'NEW STRING START AT 0
Dim xx As Integer = Array.FindIndex(oList, oTest)
messagebox.Show(xx, "xx")

 

0 Likes
Accepted solutions (2)
227 Views
3 Replies
Replies (3)
Message 2 of 4

Andrii_Humeniuk
Advisor
Advisor
Accepted solution

Hi @xenocatalyst . If you convert your array to a list you will get a FindIndex method. Example:

Dim oTest As String = "D"
Dim oList() As String = {"0", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" } 'NEW STRING START AT 0
Dim xx As Integer = oList.ToList().FindIndex(Function(n) n = oTest)
MessageBox.Show(xx, "xx")

 

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

0 Likes
Message 3 of 4

g.georgiades
Advocate
Advocate
Accepted solution

Although you still have to convert the Array to a List, you can .IndexOf without requireing a lambda.

Dim xx As Integer = oList.ToList().IndexOf(oTest)
0 Likes
Message 4 of 4

xenocatalyst
Advocate
Advocate
Hi Andrii_Humeniuk
This is the exact answer I was look for, thankyou for clarifying where it should be used.
 
thankyou for showing me a simpler way to achieve the same result.
 
 
Both of these work well.
 
 
Preview
 
 
 
0 Likes