Results 1 to 3 of 3

Thread: [RESOLVED] select text between Strings

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2004
    Posts
    12

    Resolved [RESOLVED] select text between Strings

    Is there a string function in VB.net which lets you select text between Strings?? For example:

    str1 = "This boy's name is Mike, and he likes to play soccer. Mike also likes to play basketball. This boy's name is John, and he likes to play Hockey. John also likes to play football."

    I need to select out the names, and the 2 sports they each like to play....

    Now, I've tried using str1.IndexOf() with str1.Substring(), but it wasn't very accurate. Has anyone come across something similar??

    Thanks.

  2. #2
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    Re: select text between Strings

    Something like this should work.
    VB Code:
    1. Imports System.Text.RegularExpressions
    2. ...
    3. For Each mt as Match in Regex.Matches(str1,"This boy's name is (\w+), and he likes to play (\w+). (\w+) also likes to play (\w+).")
    4. 'mt.Groups(1).tostring = first Mike
    5. 'mt.Groups(2).tostring = soccer
    6. 'mt.groups(3).tostring = second Mike
    7. 'mt.groups(4).tostring = basketball
    8. Next

  3. #3

    Thread Starter
    New Member
    Join Date
    Aug 2004
    Posts
    12

    Re: select text between Strings

    Thanks wild_bill!

    Works great!!

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