-
July 23rd, 2004, 05:22 AM
#1
How to remove the blank spaces in a string?
Hi,
I have a string, say for example string strTemp = "Hello how are you?".
Now how can i remove all the blank spaces in the string?
I tried using strTemp.Replace(" ","");
But this doesn't help...
Any idea how this can be done?
regards,
buddy
-
July 23rd, 2004, 08:18 AM
#2
The string manipulation functions return strings and leave the original intact.
Therefore :
Code:
string sHello = "Hello there you people";
sHello = sHello.Replace(" " , "");
This works.
Darwen.
-
July 23rd, 2004, 08:34 AM
#3
-
July 23rd, 2004, 08:57 PM
#4
There is a good method in string's method, String.Trim().
It removes all space from the string.
you can also use "Hello how are you?".Trim();
Ee.... Sugoi Ne~~
-
July 24th, 2004, 01:04 AM
#5
Trim() removes all whitespace characters from the start and the end of the string - not all the spaces in the string.
"Hello there you people" trimmed = "Hello there you people"
" Hello there " trimmed = "Hello there".
Darwen.
-
December 12th, 2010, 12:58 PM
#6
Re: How to remove the blank spaces in a string?
-
December 12th, 2010, 09:57 PM
#7
Re: How to remove the blank spaces in a string?
-
July 17th, 2013, 10:53 AM
#8
Re: How to remove the blank spaces in a string?
Am trying to clear the blank spaces in between the text which looks like this.
go
go
is there a way we can trim the blank spaces.
tried using text.replace(" ","") - did not work.
-
July 17th, 2013, 01:33 PM
#9
Re: How to remove the blank spaces in a string?
FOund a solution works fine
random.Text = Regex.Replace(random.Text, @"((?<=^|\n)\s*\n)|(\s*$)", string.Empty);
This trims away all the blank spaces present in the text or a string.
Thanks
-
July 17th, 2013, 02:00 PM
#10
Re: How to remove the blank spaces in a string?
Originally Posted by jakejoker
tried using text.replace(" ","") - did not work.
Post #2 explained why text.Replace() doesn't work as you have it coded.
Actually it does work, but you need to reassign the Replace() method back to the string. So the following will work:
Code:
text = text.Replace(" ", "");
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|