Alex Rivera | Logout

How to remove all white space from the beginning or end of a string?

Asked 2010-08-01T12:08:01.780
266

How can I remove all white space from the beginning and end of a string?

Like so:

"hello" returns "hello"
"hello " returns "hello"
" hello " returns "hello"
" hello world " returns "hello world"

Edit
Report

1 Answer

22
string a = "   Hello   ";
string trimmed = a.Trim();

trimmed is now "Hello"

answered 2010-08-01T12:10:10.173

Your Answer