Tuesday, December 25, 2012

Remove white spaces in a string. - C#.NET

The most common method used to remove white spaces from a string is Trim() function.

See the below example.

string name = " chamara janaka ";

as you can see there are three white spaces in the original string at the start, end and in between. When you use Trim() it will only remove white space from the end and the start of the string.

so the out put will be
"chamara janaka"

You can use Replace() function to remove all white spaces.

Response.Write(name.Replace(" ", ""));

Output will be

No comments:
Write comments
Recommended Posts × +