Home  >  Article  >  Backend Development  >  C# Detailed explanation of how to delete numbers or non-numbers in a string based on regular expressions

C# Detailed explanation of how to delete numbers or non-numbers in a string based on regular expressions

黄舟
黄舟Original
2017-06-04 09:36:352063browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn