- 时间:2020-04-12 11:41 编辑: 来源: 阅读:
- 扫一扫,手机访问
摘要:C#基于正则表达式删除字符串中数字或非数字的方法
本文实例讲述了C#基于正则表达式删除字符串中数字或非数字的方法。分享给大家供大家参考,具体如下:
/// 去掉字符串中的数字
public static string RemoveNumber(string key)
{
return Regex.Replace(key, @"\d", "");
}
//去掉字符串中的非数字
public static string RemoveNotNumber(string key)
{
return Regex.Replace(key, @"[^\d]*", "");
}
[b]PS:这里再为大家提供2款非常方便的正则表达式工具供大家参考使用:[/b]
[b]JavaScript正则表达式在线测试工具:
[/b][url=http://tools.jb51.net/regex/javascript]http://tools.jb51.net/regex/javascript[/url]
[b]正则表达式在线生成工具:
[/b][url=http://tools.jb51.net/regex/create_reg]http://tools.jb51.net/regex/create_reg[/url]
更多关于C#相关内容感兴趣的读者可查看本站专题:《[url=http://www.1sucai.cn/Special/344.htm]C#正则表达式用法总结[/url]》、《[url=http://www.1sucai.cn/Special/792.htm]C#编码操作技巧总结[/url]》、《[url=http://www.1sucai.cn/Special/266.htm]C#中XML文件操作技巧汇总[/url]》、《[url=http://www.1sucai.cn/Special/165.htm]C#常见控件用法教程[/url]》、《[url=http://www.1sucai.cn/Special/125.htm]WinForm控件用法总结[/url]》、《[url=http://www.1sucai.cn/Special/116.htm]C#数据结构与算法教程[/url]》、《[url=http://www.1sucai.cn/Special/478.htm]C#面向对象程序设计入门教程[/url]》及《[url=http://www.1sucai.cn/Special/227.htm]C#程序设计之线程使用技巧总结[/url]》
希望本文所述对大家C#程序设计有所帮助。