|
-
Oct 30th, 2008, 05:42 AM
#1
Thread Starter
Hyperactive Member
-
Oct 30th, 2008, 06:28 AM
#2
Re: [2005] Locating strings
-
Oct 30th, 2008, 06:32 AM
#3
Member
Re: [2005] Locating strings
You can use instr to return the position:
Dim position as integer = instr(textbox1.text, string1)
If you want it to be case insensitive then use:
instr(textbox1.text, string1, CompareMethod.Text)
-
Oct 30th, 2008, 06:36 AM
#4
Re: [2005] Locating strings
-
Oct 30th, 2008, 06:49 AM
#5
Member
Re: [2005] Locating strings
instr may be old school but it does return the zero based position (17 in the example) - IndexOf returns 16.
Not that it really matters so long as you know which you are getting.
-
Oct 30th, 2008, 07:15 AM
#6
Re: [2005] Locating strings
but did the OP know that (almost?) everything is zero-based, and therefore 16 was really the correct answer? instr returns a 1 Based value.
Last edited by dbasnett; Oct 30th, 2008 at 07:22 AM.
-
Oct 30th, 2008, 07:26 AM
#7
Re: [2005] Locating strings
Code:
Dim aString As String = "hello everyone, nice weather today!"
Debug.WriteLine(InStr(aString, "nice").ToString)
Debug.WriteLine(aString.IndexOf("nice").ToString)
-
Oct 30th, 2008, 07:30 AM
#8
Member
Re: [2005] Locating strings
instr returns a 1 Based value
That's what I meant to say - got it backwards when I posted (not paying enough attention, sorry).
-
Oct 30th, 2008, 07:44 AM
#9
Thread Starter
Hyperactive Member
Re: [2005] Locating strings
Thanks to all for your help!
If my post has been helpful, please rate it! 
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
|