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


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

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

其他:

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

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM