Home > Article > Backend Development > C# Detailed explanation of how to delete numbers or non-numbers in a string based on regular expressions
This article mainly introduces C#Based on regularexpressionDeleting numbers or numbers in string The non-numeric method involves C#'s simple regular matching operation skills for numbers. Friends in need can refer to the following
This article describes the C# method of deleting numbers or non-numbers in a string based on regular expressions. Share it with everyone for your reference, the details are as follows:
/// 去掉字符串中的数字 public static string RemoveNumber(string key) { return Regex.Replace(key, @"\d", ""); } //去掉字符串中的非数字 public static string RemoveNotNumber(string key) { return Regex.Replace(key, @"[^\d]*", ""); }
The above is the detailed content of C# Detailed explanation of how to delete numbers or non-numbers in a string based on regular expressions. For more information, please follow other related articles on the PHP Chinese website!