Hello
I have this code:
string s;
s = "12345 ";
How can i delete that space from my string?
I want to obtain true from this if:
if(s == "12345")
MessageBox.Show("It's correct!");
else
MessageBox.Show("Wrong");
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Sascha BPosted Mar 22, 2011, 6:28 AM
VulpesPosted Mar 23, 2011, 5:24 AM
Suthish NairPosted Mar 23, 2011, 2:46 AM
The biggest problem is that it creates more string copies each time it is called. This can often lead
to measurable performance problems in large projects. Microsoft notes that "This method does not
modify the value of the current instance. Instead, it returns a new string in which all occurrences
of oldValue are replaced by newValue."
Yo must use as below instead of Replace...
if(s.Trim() == "12345")
Sam HobbsPosted Mar 22, 2011, 4:21 PM
Raul JuncPosted Mar 22, 2011, 4:15 PM
Mahesh ChandPosted Mar 21, 2011, 8:22 PM
Here is the code snippet.
http://www.c-sharpcorner.com/uploadfile/mahesh/2886/
Sam HobbsPosted Mar 21, 2011, 7:40 PM