Monday, April 9, 2012

Split string with more than one char as delimiter


To split an string with a delimiter with more than one character like;
This is my list \r\nOranges \r\nApples \r\nGrapes
you can use:



//

string[] sArray = System.Text.RegularExpressions.Regex.Split(value, "\r\n");

//


Another option that works faster is:


//

char[] delimiters = new char[] { '\r', '\n' };
string[] sArray = MyString.Split(delimiters, StringSplitOptions.RemoveEmptyEntries);

//

No comments:

Post a Comment