Results 1 to 6 of 6

Thread: (Resolved) Get the next two words after I find a string.

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2003
    Location
    Three Rivers, MI
    Posts
    354

    (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:
    1. Private Function FindText(ByVal strText As String) As String
    2.         Return InStr(strText, "Created for")  
    3.     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

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,423

    Re: Get the next two words after I find a string.

    try this:

    vb Code:
    1. Private Function FindText(ByVal strText As String) As integer
    2.     Return strText.indexof("Created for")      
    3. End Function
    4.  
    5. dim text as string = (your text)
    6. dim firstName as string = text.substring(FindText(text) + 12).split(" "c)(0)
    7. dim lastName as string = text.substring(FindText(text) + 12).split(" "c)(1)

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2003
    Location
    Three Rivers, MI
    Posts
    354

    Re: Get the next two words after I find a string.

    Am I doing this right?

    VB Code:
    1. Private Sub ConcatText(ByVal strText As String)
    2.         ' dim text as string = (your text)
    3.         Dim firstName As String = Text.Substring(FindText(Text) + 12).Split(" "c)(0)
    4.         Dim lastName As String = Text.Substring(FindText(Text) + 12).Split(" "c)(1)
    5.         MessageBox.Show(lastName + firstName)
    6.     End Sub
    7.  
    8.     Private Function FindText(ByVal strtext As String) As String
    9.         Return strtext.IndexOf("Created for")
    10.     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.

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2003
    Location
    Three Rivers, MI
    Posts
    354

    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.

  5. #5
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,423

    Re: (Resolved) Get the next two words after I find a string.

    Return strtext.IndexOf("Created for") returns an integer

  6. #6
    Master Of Orion ForumAccount's Avatar
    Join Date
    Jan 2009
    Location
    Canada
    Posts
    2,802

    Re: (Resolved) Get the next two words after I find a string.

    vb.net Code:
    1. Dim input As String = "Created for Bill Smith Bill Smith 100 Maple St. Nowhere, MI 49091 PROGRAM INFORMATION UNDECIDED ABOUT YOUR CAREER PATH?"
    2. 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
  •  



Click Here to Expand Forum to Full Width