Home > Backend Development > C#.Net Tutorial > 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

黄舟
Release: 2017-06-04 09:36:35
Original
2099 people have browsed it

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]*", "");
}
Copy after login

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!

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template