- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Removing 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
- Related Articles
- Removing whitespaces using C# Regex
- Arranging lexicographically and removing whitespaces in JavaScript
- Removing empty fields from MongoDB
- Remove the whitespaces from a string using replace() in JavaScript?
- Removing empty array elements in PHP
- Remove all whitespaces from string - JavaScript
- Removing punctuations from a string using JavaScript
- Shedding a string off whitespaces in JavaScript
- Removing all spaces from a string using JavaScript
- Removing duplicates and inserting empty strings in JavaScript
- Delete all whitespaces from a String in Java
- C# Program to remove whitespaces in a string
- Removing all the empty indices from array in JavaScript
- Java Program to Remove All Whitespaces from a String
- Golang program to remove all whitespaces from a string

Advertisements