📌  相关文章
📜  c# 使用正则表达式替换字符串中无效的字符 - C# 代码示例

📅  最后修改于: 2022-03-11 14:48:59.289000             🧑  作者: Mango

代码示例1
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.