I have the following string with spaces before and after it:
string str = " hello world ";
How can I remove all spaces before and after the "hello world"? But not the space between hello world?
I have the following string with spaces before and after it:
string str = " hello world ";
How can I remove all spaces before and after the "hello world"? But not the space between hello world?
You can use Trim function
string str = " hello world ";
str=str.Trim();
Trim removes the spaces from both the ends only not in between
use can call Trim() function on your string to remove all white spaces in your string.
Try This:
str=str.Trim();