jsctechy
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>;thir dName <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?
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
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?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Jake,
In your code strReturn is the actual string that hold the values?
"Somename <ad@somedomain.com>; " & _
"someothename<ed@somedomai n.com>;thi rdName <th@somedomian.com>"
In your code strReturn is the actual string that hold the values?
"Somename <ad@somedomain.com>; " & _
"someothename<ed@somedomai
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
Regex should work fine, but is more complicated, and splitting will work faster than using the Regex...
Jake
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.RemoveE
' Cycle through the split strings...
For i As Integer = 0 To str.Length - 1
Mail.To.Add(str(i))
Next
Good luck,
Jake