Thursday, December 23, 2010

OverCome of string.Split(char) limitation

String split method take chat as input, bur some time may be possible that this char added on string by user. so we need to add some combination of char for less possibility of this incident.

Example code is as follows :

const string DelimiterAndSpliter = "||";
string delimitedString = string.Concat("Str1",DelimiterAndSpliter,"Str2",DelimiterAndSpliter,"Str3",DelimiterAndSpliter,"str4", DelimiterAndSpliter,"str5");
string[] stringArray = System.Text.RegularExpressions.Regex.Split(delimitedString, System.Text.RegularExpressions.Regex.Escape(DelimiterAndSpliter));

Mahesh K Sharma.

No comments: