Thursday, December 30, 2010

C# How to remove blank space in string

A blank space is not equal to “”, null or empty. It is actually a good approach to remove blank spaces from start and end of an input before saving it or doing any further processing on it. System.String class provide three trim methods to remove these spaces.


Trim()

This method removes blank spaces from start and end of a string

string input;

input .Trim();


TrimEnd
()

TrimEnd removes blank spaces from end of a string

string input;

input .TrimEnd();


TrimStart()

Use TrimStart() to remove blank spaces from start of a string

string input;

input .TrimEnd();

No comments:

Post a Comment