(Resolved) Get the next two words after I find a string.
Quote:
Created for Bill Smith Bill Smith 100 Maple St. Nowhere, MI 49091 PROGRAM INFORMATION UNDECIDED ABOUT YOUR CAREER PATH?
I can find the position where "Created for" occurs in the string
VB Code:
Private Function FindText(ByVal strText As String) As String
Return InStr(strText, "Created for")
End Function
I am trying to get the first and last name that occurs right after the "Created for" in that string but I have not found a good way to do so.
Essentialy there are multiple files in a directory that I am spinning though and changing the name of the files to match the name in the file.
Re: Get the next two words after I find a string.
try this:
vb Code:
Private Function FindText(ByVal strText As String) As integer
Return strText.indexof("Created for")
End Function
dim text as string = (your text)
dim firstName as string = text.substring(FindText(text) + 12).split(" "c)(0)
dim lastName as string = text.substring(FindText(text) + 12).split(" "c)(1)
Re: Get the next two words after I find a string.
Am I doing this right?
VB Code:
Private Sub ConcatText(ByVal strText As String)
' dim text as string = (your text)
Dim firstName As String = Text.Substring(FindText(Text) + 12).Split(" "c)(0)
Dim lastName As String = Text.Substring(FindText(Text) + 12).Split(" "c)(1)
MessageBox.Show(lastName + firstName)
End Sub
Private Function FindText(ByVal strtext As String) As String
Return strtext.IndexOf("Created for")
End Function
I am getting an error: startIndex cannot be larger than length of string. Parameter name: startIndex
I am not sure if it matters or not but the character string I am looking for is moe then 1000 characters in the document and not at the beginning like it may appear from my original post.
Re: Get the next two words after I find a string.
Never mind. I just realized I didn't un comment a line. I am all set now. Thank you!
Re: (Resolved) Get the next two words after I find a string.
Return strtext.IndexOf("Created for") returns an integer
Re: (Resolved) Get the next two words after I find a string.
vb.net Code:
Dim input As String = "Created for Bill Smith Bill Smith 100 Maple St. Nowhere, MI 49091 PROGRAM INFORMATION UNDECIDED ABOUT YOUR CAREER PATH?"
MessageBox.Show(Regex.Match(input, "(?i:(?<=Created\sFor\s))\w+\s\w+").Value)