Removes the non numeric chars by regex. - CSharp System.Text.RegularExpressions

CSharp examples for System.Text.RegularExpressions:Match Number

Description

Removes the non numeric chars by regex.

Demo Code


using System.Text.RegularExpressions;
using System.Text;
using System.Globalization;
using System.Diagnostics.CodeAnalysis;
using System;/*ww w.j a va2  s.c om*/

public class Main{
        /// <summary>
		/// Removes the non numeric chars.
		/// </summary>
		/// <returns>The non numeric.</returns>
		/// <param name="source">The source string.</param>
		[SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly", MessageId = "NonNumeric", Justification = "Ok.")]
		public static string RemoveNonNumeric(this string source)
		{
			return Regex.Replace(source, "[^0-9]*", String.Empty);
		}
}

Related Tutorials