Re: Simple String split



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
.



Relevant Pages

  • Re: Simple String split
    ... RobinS skrev: ... Note that the order of entries in crlfs ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Simple String split
    ... RobinS skrev: ... Note that the order of entries in crlfs ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Simple String split
    ... Note that the order of entries in crlfs ... I'll keep it in a handy place. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: How to get SanDisk - Cruzer Mini USB Stick working
    ... Oh, and with these entries, my Sony camera can't be accessed. ... I grabbed an rpm from somewhere ...
    (Fedora)
  • Re: composite key question
    ... >why you state that "the index associated with the primary key ... someone named "Jansen" lives, you'd quickly find the "J" entries, skip to ... the street name of this entry. ...
    (microsoft.public.sqlserver.programming)