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

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

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

其他:

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

 

posted @ 2019-02-13 09:31  万城归  阅读(8712)  评论(0编辑  收藏  举报