tokenize string
-
string strInput= "plotno 55,xx street,yy city";
char[] delimiters = { ',', '#', ';', ' ', '/', '\0', '&', '-' };
string[] strTemp = strInput.Split(delimiters, StringSplitOptions.RemoveEmptyEntries);
foreach (string a in strTemp)
{Console.WriteLine(" token'd string is\\t{0}\\t", a);
the ouput of the above code is token'd string is plotno token'd string is 55 token'd string is xx token'd string is street token'd string is yy token'd string is city it doesnt takes the specified delimiters as a token..... how to tokenenize icluding delimiters... thanks
the quieter u become more u hear
-
string strInput= "plotno 55,xx street,yy city";
char[] delimiters = { ',', '#', ';', ' ', '/', '\0', '&', '-' };
string[] strTemp = strInput.Split(delimiters, StringSplitOptions.RemoveEmptyEntries);
foreach (string a in strTemp)
{Console.WriteLine(" token'd string is\\t{0}\\t", a);
the ouput of the above code is token'd string is plotno token'd string is 55 token'd string is xx token'd string is street token'd string is yy token'd string is city it doesnt takes the specified delimiters as a token..... how to tokenenize icluding delimiters... thanks
the quieter u become more u hear
Use a Regular Expression instead.
-
Use a Regular Expression instead.
but input will be from array list... is it possible to pass array list as input to regex
the quieter u become more u hear
-
string strInput= "plotno 55,xx street,yy city";
char[] delimiters = { ',', '#', ';', ' ', '/', '\0', '&', '-' };
string[] strTemp = strInput.Split(delimiters, StringSplitOptions.RemoveEmptyEntries);
foreach (string a in strTemp)
{Console.WriteLine(" token'd string is\\t{0}\\t", a);
the ouput of the above code is token'd string is plotno token'd string is 55 token'd string is xx token'd string is street token'd string is yy token'd string is city it doesnt takes the specified delimiters as a token..... how to tokenenize icluding delimiters... thanks
the quieter u become more u hear
-
in the example which you have provided, the string has been split based on your delimiters i.e. ',' and ' '. Do you want the delimiters also to appear in the output ?
hmmm. yes .. can u help me
the quieter u become more u hear
-
but input will be from array list... is it possible to pass array list as input to regex
the quieter u become more u hear
Have you tried Regex.Split ? With the input pattern like "(,)|(#)|(;)|( )|(/)|(&)|(-)" string pattern = "(,)|(#)|(;)|( )|(/)|(&)|(-)"; string[] splitOutput = Regex.Split(input, pattern); (the option for ; in the pattern is replaced by the smiley in the post :) )