Re: Simple String split
- From: Jon Skeet [C# MVP] <skeet@xxxxxxxxx>
- Date: Wed, 12 Mar 2008 08:03:06 -0000
RobinS <robins@xxxxxxxxxxxxxxxx> wrote:
<snip>
If you don't know how the strings are "newlined", couldn't you test for \n,
\r, and \r\n? This is how I do it. Note that the order of entries in crlfs
is important.
string[] crlfs = { "\r\n", "\n", "\r" };
string[] lines = myText.Split(crlfs, StringSplitOptions.None);
Unless you really need to keep empty lines, that's more easily don as:
string[] lines = myText.Split(new[] {'\r', '\n'},
StringSplitOptions.RemoveEmptyEntries);
--
Jon Skeet - <skeet@xxxxxxxxx>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk
.
- Follow-Ups:
- Re: Simple String split
- From: RobinS
- Re: Simple String split
- References:
- Simple String split
- From: AMP
- Re: Simple String split
- From: Pipo
- Re: Simple String split
- From: Jon Skeet [C# MVP]
- Re: Simple String split
- From: RobinS
- Simple String split
- Prev by Date: Re: SerialPort.Open() Exception
- Next by Date: Re: How to force the program to continue after unhandled exception detection
- Previous by thread: Re: Simple String split
- Next by thread: Re: Simple String split
- Index(es):
Relevant Pages
|