Re: Simple String split
- From: "RobinS" <robins@xxxxxxxxxxxxxxxx>
- Date: Wed, 12 Mar 2008 12:42:05 -0700
"Jon Skeet [C# MVP]" <skeet@xxxxxxxxx> wrote in message news:MPG.22419e91342e422bad9@xxxxxxxxxxxxxxxxxxxxxxx
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);
<snip>
Cool. I actually DO need the empty lines. I am using it to stuff persisted text into a multi-line textbox, so rather than "string[] lines", my code says "myTextBox.Lines = ..."
Thanks for the tip, though. I'll keep it in a handy place.
RobinS.
GoldMail.com
.
- Follow-Ups:
- Re: Simple String split
- From: Bjorn Brox
- Re: Simple String split
- From: Bjorn Brox
- 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
- Re: Simple String split
- From: Jon Skeet [C# MVP]
- Simple String split
- Prev by Date: Re: cast of arrays with a given type
- Next by Date: Re: Windows Forms apps and various versions of .NET and Visual Studio
- Previous by thread: Re: Simple String split
- Next by thread: Re: Simple String split
- Index(es):
Relevant Pages
|