且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

需要C#正则表达式替换字符串里的空格

更新时间:2023-02-26 08:49:16

使用常规expresion查找引号,并使用替换替换空格:

Use a regular expresion to find the quotes, and a plain Replace to replace the spaces:

str = Regex.Replace(str, @"""[^""]+""", m => m.Value.Replace(' ', '|'));