Menu
Newbedev LogoNEWBEDEV Python Javascript Linux Cheat sheet
Newbedev LogoNEWBEDEV
  • Python 1
  • Javascript
  • Linux
  • Cheat sheet
  • Contact

How to remove all whitespace characters from a String?

Try using Linq in order to filter out white spaces:

  using System.Linq;

  ... 

  string source = "abc    \t def\r\n789";
  string result = string.Concat(source.Where(c => !char.IsWhiteSpace(c)));

  Console.WriteLine(result);

Outcome:

abcdef789

One way is to use Regex

public static string ReplaceAllWhiteSpaces(string str) {
  return Regex.Replace(str, @"\s+", String.Empty);
}

Taken from: https://codereview.stackexchange.com/questions/64935/replace-each-whitespace-in-a-string-with-20

Tags:

C#

String

Whitespace

Related

Spring Boot 2 health actuator default mapping Aruco markers with openCv, get the 3d corner coordinates? select2 is not showing arrow down icon onaudioprocess not called on ios11 sonarqube + lombok = false positives Material radio button change event Angular 4 Floating action button's label Azure: 409 Conflict: Cannot delete directory. It is either not empty or access is not allowed Xcode UIView.init(frame:) must be used from main thread only Laravel manual login function How to find exact error line in laravel 5.4 blade? How to get the localStorage with Python and Selenium WebDriver

Recent Posts

Pandas how to find column contains a certain value Recommended way to install multiple Python versions on Ubuntu 20.04 Build super fast web scraper with Python x100 than BeautifulSoup How to convert a SQL query result to a Pandas DataFrame in Python How to write a Pandas DataFrame to a .csv file in Python
© 2021 newbedevPrivacy Policy