FindIndex using Predicate, search for Partial match.

How do I use a FindIndex using a Predicate to match on a string that is not an exact match, but that begins with my search string.

for example, I want to find the index of the first occurrence of  "This is the string I want"    And the list will contain an element like,  "This is the string I want for 9/2/2015", where the date is not always the say.
LVL 1
HLRosenbergerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rgonzo1971Commented:
Hi,

pls try

int index = txtLines.FindIndex(x => x.StartsWith("This is the string I want"));

Regards
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
HLRosenbergerAuthor Commented:
Here's what I have.  Syntax wise, How do I make that change?

idx1 = eles.FindIndex(Function(dataValue As TextElement)
                                            Return dataValue.value = TableName
                                      End Function)
0
HLRosenbergerAuthor Commented:
like, this?

idx1 = eles.FindIndex(Function(dataValue As TextElement)
                                  Return dataValue.value.StartsWith("This is the string I want"))
                              End Function)
0
it_saigeDeveloperCommented:
Like this - (For a case-insensitive search):
idx1 = eles.FindIndex(Function(x) x.StartsWith("this is the string i want", StringComparison.OrdinalIgnoreCase))

Open in new window

Like this - (For a case-sensitive search):
idx1 = eles.FindIndex(Function(x) x.StartsWith("This is the string I want"))

Open in new window

Proof of concept:
Module Module1
	ReadOnly lines As New List(Of String) From _
	 { _
	  "Testing line", _
	  "Line Tester", _
	  "This is the string I want for 9/2/2015", _
	  "Line Tester", _
	  "Testing Line", _
	  "Testing line", _
	  "Line Tester", _
	  "This is the string I want for 9/2/2015", _
	  "Line Tester", _
	  "Testing Line" _
	 }

	Sub Main()
		Dim i As Integer = lines.FindIndex(0, Function(x) x.StartsWith("ThiS IS ThE StrinG I WanT", StringComparison.OrdinalIgnoreCase))
		While i <> -1
			Console.WriteLine("At index - [{0}]; you will find - {1}", i, lines(i))
			i = If(lines.Count - 1 >= i + 1, lines.FindIndex(i + 1, Function(x) x.StartsWith("ThiS IS ThE StrinG I WanT", StringComparison.OrdinalIgnoreCase)), -1)
		End While
		Console.ReadLine()
	End Sub
End Module

Open in new window

Produces the following output -Capture.JPG-saige-
0
HLRosenbergerAuthor Commented:
thanks!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.