Introducing Radical.sh

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

Remove all spaces in a string using Regex in C#

Using REGEX you can remove the spaces in a string.

The following namespace is mandatory.
using System.Text.RegularExpressions;


Syntax:
Regex.Replace(text, @"\s", "")


Example:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

namespace ForgetCode
{
    class Program
    {
       static void Main(string[] args)
        {
            string text = "  My name is Forget Code  ";
            Console.WriteLine(Regex.Replace(text, @"\s", ""));            
        }
    }
}


Output:
MynameisForgetCode