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

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.

Comments:

Add a Comment:

simple_captcha.jpg
(human authentication)


Ads

Categories

About

Random foliage

This website is meant to be a reference for ASP Dot Net developers. The entries are a compilation of things I've figured out how to do and that I deem useful to keep of track for future reference. Assumptions: web development with: C Sharp (vb sucks), visual studio 05/08, .net 3.5, meant for programmers. Written by: James Reategui.