|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
String.Split()Hello,
Is it possible to split a string at the combination "\r\n" for eg:- string str = "domain\r\nisnetwork" Output required :- domain isnetwork <nethr***@gmail.com> wrote:
> Is it possible to split a string at the combination "\r\n" Yes, but not with String.Split. Regex.Split will do it:> > for eg:- string str = "domain\r\nisnetwork" > > Output required :- > > domain > isnetwork using System; using System.Text.RegularExpressions; class Test { static void Main() { string[] bits = Regex.Split ("hello\r\nthere\r\nJon", "\\r\\n"); foreach (string bit in bits) { Console.WriteLine ("xxx"+bit+"xxx"); } } } (Note that the "xxx" parts are for clarity of testing - because if it got one bit which was "hello\r\nthere" it would still appear on two lines!) If you're doing this frequently in an app, it would be worth precompiling the regular expression. -- Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet If replying to the group, please do not mail me too |
|||||||||||||||||||||||