C#去掉字符串中的特殊字符
方案一:
string except_chars = ": ‘ ! @ # % … & * ( ^ & ¥ , 。 , .)$";
string src = "就是包含: 这些‘字符 包含空格)都要$去掉么?";
string result = Regex.Replace(src, "[" + Regex.Escape(except_chars) + "]", "");
方案二:
//只保留字母、数字 和汉字
string strAfter= Regex.Replace(strBefor, @"[^a-zA-Z0-9\u4e00-\u9fa5\s]", "");
实例:
/// <summary>
/// 判断该样本商品是否已存在
/// </summary>
/// <param name="model"></param>
/// <returns>存在:true</returns>
public bool IsExist(ClassifyCorrectionPanelPool model)
{
bool isExist = false;
List<ClassifyCorrectionPanelPool> modelList = LoadEntities(a => a.CODE_TS.Equals(model.CODE_TS) && a.G_NAME.Equals(model.G_NAME)).ToList(); if (modelList.Count > )
{
foreach (var item in modelList)
{
string GModelrep = Regex.Replace(item.G_MODEL, @"[^a-zA-Z0-9\u4e00-\u9fa5\s]", ""); string addGModelRep = Regex.Replace(model.G_MODEL, @"[^a-zA-Z0-9\u4e00-\u9fa5\s]", ""); if (GModelrep.Equals(addGModelRep))
{
isExist= true;
}
}
}
return isExist;
}
C#去掉字符串中的特殊字符的更多相关文章
- C++去掉字符串中首尾空格和所有空格
c++去掉首尾空格是参考一篇文章的,但是忘记文章出处了,就略过吧. 去掉首尾空格的代码如下: void trim(string &s) { if( !s.empty() ) { s.erase ...
- C# 使用正则表达式去掉字符串中的数字,或者去掉字符串中的非数字
/// 去掉字符串中的数字 public static string RemoveNumber(string key) { ...
- 三种java 去掉字符串中的重复字符函数
三种java 去掉字符串中的重复字符函数 public static void main(string[] args) { system.out.println(removerepeatedchar( ...
- 正则匹配去掉字符串中的html标签
1.得到超链接中的链接地址: string matchString = @"<a[^>]+href=\s*(?:'(?<href>[^']+)'|"&quo ...
- C# 使用正则表达式去掉字符串中的数字
/// <summary>/// 去掉字符串中的数字/// </summary>/// <param name="key"></param ...
- 【PHP函数】PHP 去掉字符串中的转义符号
PHP字符串中的转义符号 string stripslashes ( string $str ) //去掉字符串中的反斜线字符.若是连续二个反斜线,则去掉一个,留下一个.若只有一个反斜线,就直接去掉.
- PHP用正则匹配字符串中的特殊字符防SQL注入
本文出至:新太潮流网络博客 /** * [用正则匹配字符串中的特殊字符] * @E-mial wuliqiang_aa@163.com * @TIME 2017-04-07 * @WEB http:/ ...
- C# .net 使用正则表达式去掉字符串中的数字
/// <summary>/// 去掉字符串中的数字/// </summary>/// <param name="key"></param ...
- 《程序员代码面试指南》第五章 字符串问题 去掉字符串中连续出现k 个0 的子串
题目 去掉字符串中连续出现k 个0 的子串 java代码 package com.lizhouwei.chapter5; /** * @Description: 去掉字符串中连续出现k 个0 的子串 ...
随机推荐
- linux命令:touch
1:命令介绍: touch用来创建文件或修改文件和目录的时间戳,包括存取时间和更改时间. 2:命令格式: touch [选项] 文件 3:命令参数: -a 或--time=atime或--time ...
- MVC学习IIS的不同版本(一)
一:IIS5.0运行在进程InetInfo.exe中,该进程寄宿着一个名为World Wide Publishing Service(W3VC)的window服务. W3VC的主要功能:包括HTTP请 ...
- AmazeUI基本样式
AmazeUI是一个轻量级.Mobile first的前端框架,基于开源社区流行的前端框架编写. Normalize AmazeUI使用了normalize.css,但做了些调整:html添加了-we ...
- Minimum Inversion Number_线段树||树状数组
Problem Description The inversion number of a given number sequence a1, a2, ..., an is the number of ...
- All X_数的快速幂
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission( ...
- 了解magento数据库
网址是:http://www.magereverse.com/,不同版本都有
- Notes of Linked Data concept and application - TODO
Motivation [反正债多了不愁,再开个方向.] Data plays a core role in most business systems, data storage and retrie ...
- yii2 文件上传
直接贴代码了 --------------------------------------------------------------------------------------------- ...
- Post和get乱码
post 在web.xml中添加 <filter> <filter-name>CharacterEncodingFilter</filter-name> <f ...
- 什么是html5
HTML5是用于取代1999年所制定的 HTML 4.01 和 XHTML 1.0 标准的 HTML 标准版本,现在仍处于发展阶段,但大部分浏览器已经支持某些 HTML5 技术.HTML 5有两大特点 ...