Introducing Radical.sh

Forget Code launches a powerful code generator for building API's

Remove all spaces in a string in C#

We can remove all the white space characters in a string by the following code.

  1. stringtext.Replace(" ", string.Empty);


Example:
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace ForgetCode
  7. {
  8. class Program
  9. {
  10. static void Main(string[] args)
  11. {
  12. string text = " My name is Forget Code ";
  13. Console.WriteLine(text.Replace(" ", string.Empty));
  14. }
  15. }
  16. }

Output:
MynameisForgetCode