[Resolved] Sub string within a string
Hi
New to VB, but not to programming.
I need to search lines of text for substrings.
I recon LastIndexOfAny is the way to go.
As an example, if I wanted to find the last occurance of the word "for"
in: "This string is just for tests purposes and should not be taken for any other reasons."
When I have tried various ways I get it returning an index of one of the letters of 'for' or at least that is what it looks like.
I would be looking for a reply of 63 for the string above (presuming I counted corectly) as it's the last occurence of for. Not a return indicating the last occurance of 'o' instead or some other reply.
Code:
current_line = "This string is just for tests purposes and should not be used for any other reasons."
count2 = current_line.LastIndexOfAny("for")
Re: Sub string within a string
I get the result of 63 using "LastIndexOf" (the first character position is zero).
Code:
Dim s As String = "This string is just for tests purposes and should not be taken for any other reasons."
MessageBox.Show(s.LastIndexOf("for"))
Re: Sub string within a string
I get 80. As though it is returning the postion of a character in another word, not the whole word. And it is the whole word I am looking for.
Re: Sub string within a string
No matter i feel stupid. Got it now.:)