Sunday 10 April 2016

Removing multiple white-space or from string using c#




// Function
System.Text.RegularExpressions.Regex.Replace('string', 'regular exp', 'white-space');

// Exp
string Str="sdf  asd    asdf sdfas  asdf      asdf   asdf sdf    asdf        asdf    asdf";

string cleanedString = System.Text.RegularExpressions.Regex.Replace(Str, @"\s+", " ");

// Result

cleanedString ="sdf asd asdf sdfas asdf asdf asdf sdf asdf asdf asdf";

No comments:

Post a Comment

Excel Sort values in ascending order using function TEXTJOIN

 Excel ::  Text ::  1,3,5,2,9,5,11 Result :: 1,2,3,5,5,9,11 Formula ::     TEXTJOIN ( ",",1,SORT(MID(SUBSTITUTE( A1 ,","...