第一種,若字符串中含有字母,則使用以下方法
public static string RemoveSpecialCharacterToupper(string hexData) { //下文中的‘\\’表示轉義 return Regex.Replace(hexData, "[ \\[ \\] \\^ \\-_*×――(^)|'$%~!@#$…&%¥—+=<>《》!!???::•`·、。,;,.;\"‘’“”-]", "").ToUpper(); }
其他:
public static string RemoveSpecialCharacter(string hexData) { //下文中的‘\\’表示轉義 return Regex.Replace(hexData, "[ \\[ \\] \\^ \\-_*×――(^)|'$%~!@#$…&%¥—+=<>《》!!???::•`·、。,;,.;\"‘’“”-]", ""); }