|
-
Sep 27th, 2009, 06:22 PM
#1
Thread Starter
Hyperactive Member
(Resolved) Get the next two words after I find a string.
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.
Last edited by BukHix; Sep 27th, 2009 at 08:27 PM.
Reason: Resolved
-
Sep 27th, 2009, 06:29 PM
#2
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)
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Sep 27th, 2009, 08:00 PM
#3
Thread Starter
Hyperactive Member
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.
-
Sep 27th, 2009, 08:21 PM
#4
Thread Starter
Hyperactive Member
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!
Last edited by BukHix; Sep 27th, 2009 at 08:27 PM.
-
Sep 28th, 2009, 10:02 AM
#5
Re: (Resolved) Get the next two words after I find a string.
Return strtext.IndexOf("Created for") returns an integer
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Sep 28th, 2009, 11:43 AM
#6
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)
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
|