|
-
Jun 17th, 2007, 05:17 PM
#1
Thread Starter
New Member
[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")
Last edited by Writers Block; Jun 17th, 2007 at 05:43 PM.
Reason: [Resolved]
-
Jun 17th, 2007, 05:23 PM
#2
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"))
-
Jun 17th, 2007, 05:37 PM
#3
Thread Starter
New Member
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.
-
Jun 17th, 2007, 05:40 PM
#4
Thread Starter
New Member
Re: Sub string within a string
No matter i feel stupid. Got it now.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|