C#基于正则表达式删除字符串中数字或非数字的方法
作者:94cool 时间:2021-07-12 17:27:44
本文实例讲述了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#程序设计有所帮助。
标签:C#,正则表达式
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Android程序开发之手机APP创建桌面快捷方式
2023-04-01 06:55:49
![](https://img.aspxhome.com/file/2023/0/89540_0s.png)
javaweb实现app扫码登录功能
2022-03-25 03:48:19
SpringBoot利用注解来实现Redis分布式锁
2022-02-13 16:57:36
![](https://img.aspxhome.com/file/2023/9/82369_0s.png)
Java的MyBatis框架中实现多表连接查询和查询结果分页
2022-10-29 08:49:21
![](https://img.aspxhome.com/file/2023/7/72397_0s.png)
Java与SpringBoot对redis的使用方式
2021-06-11 19:23:39
![](https://img.aspxhome.com/file/2023/6/78916_0s.png)
SpringCloud实现Redis在各个微服务的Session共享问题
2022-07-14 06:33:19
Spring-boot的debug调试代码实例
2023-10-17 04:49:01
Elasticsearch学习之Terms set 查询
2021-12-01 01:52:19
Android WindowManger的层级分析详解
2023-08-05 23:51:40
Android一行代码实现圆形头像
2022-02-23 02:00:25
![](https://img.aspxhome.com/file/2023/7/92577_0s.jpg)
C#利用原图和水印图的重叠简单实现水印的方法
2023-04-21 01:41:24
Java class文件格式之属性_动力节点Java学院整理
2021-06-13 01:52:00
![](https://img.aspxhome.com/file/2023/4/101944_0s.png)
Java获取彩色图像中的主色彩的实例代码
2021-10-16 01:09:39
![](https://img.aspxhome.com/file/2023/2/67172_0s.png)
Java反射 JavaBean对象自动生成插入,更新,删除,查询sql语句操作
2022-04-05 20:07:11
C#用Topshelf创建Windows服务的步骤分享
2022-10-19 00:47:58
![](https://img.aspxhome.com/file/2023/4/76414_0s.png)
Java非法字符: ‘\\ufeff‘问题及说明
2023-02-01 09:06:07
![](https://img.aspxhome.com/file/2023/3/83033_0s.png)
Spring MVC 处理一个请求的流程
2021-12-19 18:39:39
![](https://img.aspxhome.com/file/2023/1/77341_0s.png)
java实现PPT转化为PDF
2021-06-17 05:02:24
在启动后台 jar包时,使用指定的 application.yml操作
2023-01-08 20:10:12
java实现dijkstra最短路径寻路算法
2021-10-23 06:29:58