Split a string with multiple characters or newline
Posted on: Tue Aug 26 12:09:45 -0700 2008. Updated on: Tue Aug 26 12:09:45 -0700 2008.
Category: DotNet
Category: DotNet
It took me a while to figure this out but it is quite useful, specially when you want to split on a windows newline, ie. \r\n
strint str = "first line \r\n another line \r\n blank";
string[] array = str.Split(new string[] { "\r\n" }, StringSplitOptions.None);
Now you can iterate through array and have the lines nicely split. By the way, this is faster than using regex for relatively short strings, under 400 chars.