Link to home
Start Free TrialLog in
Avatar of jsctechy
jsctechyFlag for United States of America

asked on

print a line as many times a string is found (easy stuff)

hi,
I have a long string that needs to be break out and writea line per each break.
I have the following string:
"Somename <ad@somedomain.com>; someothename<ed@somedomain.com>;thirdName <th@somedomian.com>"
so what i need to do is read the string and per each ; found the write the following line:
Mail.To.Add(string found)

so from my example above this is hat it shuld write
Mail.To.Add(Somename <ad@somedomain.com>)
Mail.To.Add(someothename <ed@somedomain.com>)
Mail.To.Add(thirdName <th@somedomian.com>")

How can i write this loop?
Avatar of jake072
jake072
Flag of Canada image

This is indeed easy.

Create a string array from your source string:

' This is the array to use for splitting.
Dim strSep As String() = {";"}
' Split the source string.
Dim str As String() = strReturn.Split(strSep, StringSplitOptions.RemoveEmptyEntries)

' Cycle through the split strings...
For i As Integer = 0 To str.Length - 1
   Mail.To.Add(str(i))
Next

Good luck,

Jake
ASKER CERTIFIED SOLUTION
Avatar of VBRocks
VBRocks
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jsctechy

ASKER

Jake,
In your code strReturn is the actual string that hold the values?
"Somename <ad@somedomain.com>; " & _
            "someothename<ed@somedomain.com>;thirdName <th@somedomian.com>"
Yes - strReturn is your source string (Sorry - should've named it better).

Regex should work fine, but is more complicated, and splitting will work faster than using the Regex...

Jake