C# Code Snippet - Remove White Spaces

C# Code Snippet - Remove White Spaces

C# Code Snippet - Remove White Spaces

(C-Sharp) C# code snippet to remove all white spaces from a string. TrimWhiteSpace strip all white spaces from a given.

Bookmark:

C# Code Snippet - Remove White Spaces

This .Net C# code snippet removes all white spaces from a string. White spaces removing done by set of successful matches found by iteratively applying a regular expression pattern to the input string.

public string TrimWhiteSpace(string str)
{
    return System.Text.RegularExpressions.Regex.Replace(str, @"^\s+", string.Empty);
}


C# Keywords Used:

  • Regex
  • Replace

Code Snippet Information:

  • Applies To: .Net, C#, CLI, HTML, Regular Expression
  • Programming Language : C#

External Resources:

Leave a comment