软件编程
位置:首页>> 软件编程>> C#编程>> C#基于正则表达式删除字符串中数字或非数字的方法

C#基于正则表达式删除字符串中数字或非数字的方法

作者:94cool  发布时间:2021-07-12 17:27:44 

标签:C#,正则表达式

本文实例讲述了C#基于正则表达式删除字符串中数字或非数字的方法。分享给大家供大家参考,具体如下:


/// 去掉字符串中的数字
public static string RemoveNumber(string key)
{
 return Regex.Replace(key, @"\d", "");
}
//去掉字符串中的非数字
public static string RemoveNotNumber(string key)
{
 return Regex.Replace(key, @"[^\d]*", "");
}

PS:这里再为大家提供2款非常方便的正则表达式工具供大家参考使用:

JavaScript正则表达式在线测试工具:
http://tools.jb51.net/regex/javascript

正则表达式在线生成工具:
http://tools.jb51.net/regex/create_reg

希望本文所述对大家C#程序设计有所帮助。

0
投稿

猜你喜欢

手机版 软件编程 asp之家 www.aspxhome.com