Split String Into Array Using Multiple characters

Posted: January 18, 2012 in ASP.Net

To split a string by multiple characters into an array, you can try the following:

using System;
using System.Text.RegularExpressions;

class myClass
{
    static void Main()
    {
	string myValue = "line1\r\nline2\r\nline3";

	string[] myLines = Regex.Split(myValue , "\r\n");

	foreach (string myLine in myLines )
	{
	    Console.WriteLine(myLine);
	}
    }
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s