PDA

Click to See Complete Forum and Search --> : [RESOLVED] select text between Strings


nipahoy
Jul 28th, 2005, 09:25 AM
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.

wild_bill
Jul 28th, 2005, 11:48 PM
Something like this should work.

Imports System.Text.RegularExpressions
...
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+).")
'mt.Groups(1).tostring = first Mike
'mt.Groups(2).tostring = soccer
'mt.groups(3).tostring = second Mike
'mt.groups(4).tostring = basketball
Next

nipahoy
Jul 29th, 2005, 11:44 AM
Thanks wild_bill!

Works great!!