Tuesday, July 7, 2009

RegEx.Split vs. String.Split

String.split has some limitations in the split. but in the Regex.split will split duplicate delimeter.

The delimeter such as ||, ~~ and ::

string[] output  = null;  string inputSentence = "I am a developer|| I work on .Net || " +     "The latest framework available is 3.5";  //the following line will not work 
output = inputSentence .Split("||".ToCharArray());  
//use RegEx Split instead 
output =  System.Text.RegularExpressions.Regex.Split(inputSentence, System.Text.RegularExpressions.Regex.Escape("||"));