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
Printable View
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
The string manipulation functions return strings and leave the original intact.
Therefore :
This works.Code:string sHello = "Hello there you people";
sHello = sHello.Replace(" " , "");
Darwen.
Thanks Darwen
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();
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.
how do you do this in C?
You ask in a C forum.
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.
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
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(" ", "");