c# 正则表达式替换字符串中常见的特殊字符

第一种,若字符串中含有字母,则使用以下方法

  public static string RemoveSpecialCharacterToupper(string hexData)
        {
            //下文中的‘\’表示转义
            return Regex.Replace(hexData, "[ \[ \] \^ \-_*×――(^)|'$%~!@#$…&%¥—+=<>《》!!???::•`·、。,;,.;"‘’“”-]", "").ToUpper();
        }

其他:

  public static string RemoveSpecialCharacter(string hexData)
        {
            //下文中的‘\’表示转义
            return Regex.Replace(hexData, "[ \[ \] \^ \-_*×――(^)|'$%~!@#$…&%¥—+=<>《》!!???::•`·、。,;,.;"‘’“”-]", "");
        }
原文地址:https://www.cnblogs.com/wanchenggui/p/10368155.html