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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Sascha B122 reputationPosted Mar 22, 2011, 2:28 AM EDT
Sam HobbsRank #107 · 20.5K reputationPosted Mar 21, 2011, 3:40 PM EDT
Mahesh ChandRank #1 · 393.3K reputationPosted Mar 21, 2011, 4:22 PM EDT
Here is the code snippet.
http://www.c-sharpcorner.com/uploadfile/mahesh/2886/
Raul Junc15 reputationPosted Mar 22, 2011, 12:15 PM EDT
Sam HobbsRank #107 · 20.5K reputationPosted Mar 22, 2011, 12:21 PM EDT
Suthish NairRank #92 · 22.8K reputationPosted Mar 22, 2011, 10:46 PM EDT
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")
VulpesRank #55 · 29.2K reputationPosted Mar 23, 2011, 1:24 AM EDT