
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Remove Whitespaces Using C# String.Empty
Set the string.
StringBuilder str = new StringBuilder("Tom Hanks");
Now, use the replace() method to replace whitespace with String. Empty. This will eventually remove the whitespace.
str.Replace(" ", String.Empty);
Let us see the complete code −
Example
using System; using System.Text; class Demo { static void Main() { StringBuilder str = new StringBuilder("Tom Hanks"); Console.WriteLine(str.ToString()); str.Replace(" ", String.Empty); Console.WriteLine(str.ToString()); Console.ReadLine(); } }
Output
Tom Hanks TomHanks
Advertisements