Link to home
Start Free TrialLog in
Avatar of HLRosenberger
HLRosenbergerFlag for United States of America

asked on

Help with FindIndex method; using predicate.

I have this bit of code, below, that finds the index of the first TextElement in eles that contains the dataValue.    I want to modify it so I can pass a count and find the Nth occurrence of dataValue.

Thanks

Dim eles As New List(Of TextElement)

dim dataValue as string = 'george washington'

index = eles.FindIndex(Function(dataValue As TextElement)
                                                    Return dataValue.value = dataValue
                                        End Function)


 Private Class TextElement

        Public value As String
        Public element As XElement

    End Class
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Hi  HLRosenberger;

Try it like this.

'' Do not use a variable name the same as the variable name as in the Predicate
Dim indexOfString As String = "george washington"

Dim index = eles.FindIndex(Function(dataValue As TextElement)
                               Return dataValue.value = indexOfString
                           End Function)

Open in new window

Avatar of HLRosenberger

ASKER

I understand that I should change that variable name.   However, how does changing that variable name make is so that I can find the Nth occurrence of data?
ASKER CERTIFIED SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thanks!
Not a problem HLRosenberger, glad to help.