Re: Simple String split

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance




"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

.



Relevant Pages

  • Re: Simple String split
    ... RobinS wrote: ... Note that the order of entries in crlfs ...
    (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)
  • Re: SBS 2003 - KB 835734 - Repeating Install.....
    ... Found the reason on the SBS 2003 group in another person post. ... of my other Windows Updates. ... The entries that do exist in 835734 registry entries match up to entries ...
    (microsoft.public.windowsupdate)
  • Re: Ethernet Driver Configuration
    ... Add the DM9000 entries to this struct: ... a TARGETLIBS entry in the sources files for eboot. ...
    (microsoft.public.windowsce.embedded)