|
-
Apr 28th, 2011, 09:01 PM
#1
Thread Starter
Frenzied Member
Find String Within String = Cant be found!?!?
I was trying to do a simiple, fine a string start position, or a string, and it always returns 0
Dim My_Search_String As String
Dim My_Text As String
My_Search_String = "fsl fwb fcb"
My_Text = "here is some kind of tex fsl fwb fcb"
MessageBox.Show(InStr(1, My_Search_String, My_Text))
-
Apr 28th, 2011, 09:14 PM
#2
Re: Find String Within String = Cant be found!?!?
You're using VB.NET, so use VB.NET. Call IndexOf on your original String and pass your substring as an argument. That will either return the index of the first occurrence of the substring or else -1 if the substring isn't found.
Also, make sure you have the Strings the right way round when you use IndexOf. You have them the wrong way round at the moment, which would explain why you don't get a result? I'm not sure why I even ask but did you read the documentation to make sure that you were calling the method correctly?
Finally, I think that anyone with over 1200 posts has been coding long enough to turn Option Strict On. You should turn it On in the IDE options and then it will be On by default for every project you create.
-
Apr 28th, 2011, 09:17 PM
#3
Thread Starter
Frenzied Member
Re: Find String Within String = Cant be found!?!?
-
Apr 28th, 2011, 09:30 PM
#4
Fanatic Member
Re: Find String Within String = Cant be found!?!?
I was just looking at that. In Visual Studio it's under Debug > Options and Settings > Projects and Solutions > VB Defaults.
 Make as many mistakes as you can as quickly as you can. We want to make sure that we make a great enough number of mistakes in a given amount of time so that we can be successful.
"Persistence is the magic of success." Paramahansa Yogananda
-
Apr 28th, 2011, 09:39 PM
#5
Thread Starter
Frenzied Member
Re: Find String Within String = Cant be found!?!?
I was able to get this to work below
Dim My_Text As String
My_Text = "here is some kind of tex fsl fwb fcb some other text cool stop"
Dim bd_fieldNum As Integer = 1
Dim bd_beginStr As String = String.Format("fsl fwb fcb", bd_fieldNum)
Dim bd_beginPos As Integer = My_Text.IndexOf(bd_beginStr) + bd_beginStr.Length
Dim bd_result As String = My_Text.Substring(bd_beginPos, My_Text.IndexOf("stop", bd_beginPos) - bd_beginPos)
MessageBox.Show(bd_result)
However, when i changed it to this below, and used a dynamic set of text to search, it couldnt find anything. I did a check and popped up a message to show me the innerhtml of the element, and it was in there.
Dim My_Text As String
My_Text = element.InnerHtml.ToString
Dim bd_fieldNum As Integer = 1
Dim bd_beginStr As String = String.Format("fsl fwb fcb", bd_fieldNum)
Dim bd_beginPos As Integer = My_Text.IndexOf(bd_beginStr) + bd_beginStr.Length
Dim bd_result As String = My_Text.Substring(bd_beginPos, My_Text.IndexOf("</a>", bd_beginPos) - bd_beginPos)
MessageBox.Show(bd_result)
*********
i wanted to search for "tom" in the string "hello tom is here", i want it to give me back a number where "tom" first appears, then strip off anything before it, so the string now would be "is here" but i dont see that...
In my example i try to pull parts out, so i wanted an ending flag, that i could have, so it could get even "tom was" if "here" was my ending flag
Last edited by joefox; Apr 28th, 2011 at 10:08 PM.
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
|