0

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?

George Stocker
  • 57,289
  • 29
  • 176
  • 237
taito
  • 561
  • 2
  • 6
  • 11

2 Answers2

3

You can use Trim function

string str = "     hello world        ";
str=str.Trim();

Trim removes the spaces from both the ends only not in between

tariq
  • 2,193
  • 15
  • 26
2

use can call Trim() function on your string to remove all white spaces in your string.

Try This:

str=str.Trim();
Sudhakar Tillapudi
  • 25,935
  • 5
  • 37
  • 67