C#去除字符串中的中文
使用正则表达式
1.
///
/// 去除字符串中的中文
///
///
///
public static string DeleteChineseWord(string str)
{
string retValue = str;
if (System.Text.RegularExpressions.Regex.IsMatch(str, @”[\u4e00-\u9fa5]”))
{
retValue = string.Empty;
var strsStrings = str.ToCharArray();
for (int index = 0; index < strsStrings.Length; index++)
{
if (strsStrings[index] >= 0x4e00 && strsStrings[index] <= 0x9fa5)
{
continue;
}
retValue += strsStrings[index];
}
}
return retValue;
}
2.去除字符串中的字母
string strRemoved = Regex.Replace(needDeal, “[a-z]”, “”, RegexOptions.IgnoreCase);
needDeal为需要处理的字符串
strRemoved为处理后的字符串
3.去除字符串中的数字
string strDealed1 = Regex.Replace(needDeal, “[0-9]”, “”, RegexOptions.IgnoreCase);
needDeal为需要处理的字符串
strDealed1为处理后的字符串