string inputString = "1/10 EP Sp'arrowha?wk XT R;TR 2.4GHz Red";
//Characters Collection: (';', '\', '/', ':', '*', '?', ' " ', '<', '>', '|', '&', ''')
string outputString = "1 10 EP Sp arrowha wk XT R TR 2.4GHz Red";
答案 0 :(得分:21)
有关以下代码的完整披露:
new Regex(...)
; 我实际上并不知道C#,但我可以通过Google "C# string replace regex"
和land on MSDN
Regex re = new Regex("[;\\/:*?\"<>|&']");
string outputString = re.Replace(inputString, " ");
这是正确的代码:
string inputString = "1/10 EP Sp'arrowha?wk XT R;TR 2.4GHz R\\ed";
Regex re = new Regex("[;\\\\/:*?\"<>|&']");
string outputString = re.Replace(inputString, " ");
// outputString is "1 10 EP Sp arrowha wk XT R TR 2.4GHz R ed"
答案 1 :(得分:4)
string outputString = Regex.Replace(inputString,"[;\/:*?""<>|&']",String.Empty)
答案 2 :(得分:0)
这是替换特殊字符的Java代码
String inputString = "1/10 EP Sp'arrowha?wk XT R;TR 2.4GHz R\\ed";
String re = "[;\\\\/:*?\"<>|&']";
Pattern pattern = Pattern.compile(re);
Matcher matcher = pattern.matcher(inputString);
String outputString = matcher.replaceAll(" ");