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

How to highlight selected text in notepad++

  –> To highlight a block of code in Notepad++, please do the following steps step-1  :- Select the required text. step-2  :- Right click...