p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   C# (http://p2p.wrox.com/forumdisplay.php?f=22)
-   -   looping thru string (http://p2p.wrox.com/showthread.php?t=67689)

havey April 26th, 2008 01:23 PM

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

samjudson April 26th, 2008 05:13 PM

You say what you 'should' be getting but you don't way what you 'are' getting. I don't see the problem.

Also - temp[1] is a string - there is NO POINT in appending .ToString() to a string. If you are doing this to try to 'fix' some other problem then you are probably not understanding the other problem.

/- Sam Judson : Wrox Technical Editor -/


All times are GMT -4. The time now is 07:24 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.