View Single Post
  #1 (permalink)  
Old April 26th, 2008, 01:23 PM
havey havey is offline
Authorized User
 
Join Date: Nov 2007
Location: , , .
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default looping thru string

Hi I have a string like so:

firstname: jason | jeff^lastname: smith |^mname: robert | kevin

I am trying to split on the "^" and then split on the "|" and then check if there is a value in the second index of the "|" split.

this is what i have:

foreach (string s in Regex.Split(messageBody, "^", RegexOptions.IgnoreCase))
            {
                for (int t = 0; t < s.Length; t++)
                {
                    string[] temp = s .Split(new Char[] { '|' }, 2);
                    if (temp[1].ToString().Length > 0)
                        mBody += s + "\r\n";
                }
            }

the result should be:
firstname: jason | jeff
mname: robert | kevin

and ignor the: lastname: smith | because ther is no value after the "|"


any suggestions? thanks
Reply With Quote