I have a For Each loop that is looping through an array of strings to find the first string with a length of three characters. For example, when looping through the array, if the first 3 character string is the 4th index of the array, I would like for it to return the 3rd (previous) index of the array. Any help would be appreciated.
For Each piece As String In p
If piece.Length = 3 Then
'Return previous index
End If
Next
You have a couple of options.
If
pis a collection accessible by index (ie:IList(Of T)), you can switch to a For loop, and return the element at the current index -1.Otherwise, you can keep the previous item in a separate variable, and return it when your condition is met.