How to remove whitespaces between characters in c#?
Trim()
can be used to remove the empty spaces at the beginning of the string as well as at the end. For example " C Sharp ".Trim()
results "C Sharp"
.
But how to make the string into CSharp
? We can remove the space using a for
or a for each
loop along with a temporary variable. But is there any built in method in C#(.Net framework 3.5)
to do this like Trim()
?
strip()—Remove Leading and Trailing Spaces. The str. strip() method removes the leading and trailing whitespace from a string.
Press Shift + Alt then press the down button before "56". Then backspace . You will see the cursor becomes big and then you can remove the spaces all at once.
How to remove whitespaces between characters in c#? Trim() can be used to remove the empty spaces at the beginning of the string as well as at the end. For example " C Sharp ". Trim() results "C Sharp" .
To remove whitespace characters from the beginning or from the end of a string only, you use the trimStart() or trimEnd() method.
You could use String.Replace method
string str = "C Sharp"; str = str.Replace(" ", "");
or if you want to remove all whitespace characters (space, tabs, line breaks...)
string str = "C Sharp"; str = Regex.Replace(str, @"\s", "");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With