Deleting Spaces From String!

Posts 1–5 of 5 · Page 1 of 1
Deleting Spaces From String!
I get an error for string.replace!
Basically I want to replace the spaces in the old string with nothing.

So it would end up like "12312312123"

Code:
string old = "123 12312 123"
string new = old.replace(L" ", string.empty());
this belongs to C# section and its:
string newStr = old.Trim();

Plus String.Empty is a field not a method.
Quote Originally Posted by user590177 View Post
this belongs to C# section and its:
string newStr = old.Trim();

Plus String.Empty is a field not a method.
It is most certainly NOT old.Trim();

Trim is for leading/trailing characters.

Code:
string old = "123 12312 123";
string newStr = old.Replace(" ", string.Empty);
Quote Originally Posted by Jason View Post


It is most certainly NOT old.Trim();

Trim is for leading/trailing characters.

Code:
string old = "123 12312 123";
string newStr = old.Replace(" ", string.Empty);
I thought Trim() removed the spaces at the front and back of a string.

Or is that what leading and trailing means? My English is fucked right now.
Quote Originally Posted by Nathan View Post


I thought Trim() removed the spaces at the front and back of a string.

Or is that what leading and trailing means? My English is fucked right now.
Yup. You are right, but he wants to remove all spaces I believe. Not just leading and trailing spaces.
Posts 1–5 of 5 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Need help?