📅  最后修改于: 2022-03-11 14:48:59.289000             🧑  作者: Mango
string pattern = "[\\~#%&*{}/:<>?|\"-]";
string replacement = " ";
Regex regEx = new Regex(pattern);
string sanitized = Regex.Replace(regEx.Replace(input, replacement), @"\s+", " ");
This will replace runs of whitespace with a single space as well.