Removes the punctuations by regex. - CSharp System.Text.RegularExpressions

CSharp examples for System.Text.RegularExpressions:Match String

Description

Removes the punctuations by regex.

Demo Code


using System.Text.RegularExpressions;
using System.Text;
using System.Globalization;
using System.Diagnostics.CodeAnalysis;
using System;//from w  w  w .  j  ava 2 s.  c  o m

public class Main{
        /// <summary>
		/// Removes the punctuations.
		/// </summary>
		/// <returns>The clean string.</returns>
		/// <param name="source">The source string.</param>
		public static string RemovePunctuations(this string source)
		{
			return Regex.Replace(source, @"[!\(\)\[\]{}\:;\.,?'""]*", String.Empty);
		}
}

Related Tutorials