string query = "A|B";
接下来的两行的输出等于"%A%|%B%"
,而预期“A%B”!
query = Regex.Replace(query, "|", "%");
query = Regex.Replace(query, @"|", "%");
为什么?
答案 0 :(得分:4)
The |
is a special character of regexes, it means "or"。你必须逃脱它。
query = Regex.Replace(query, @"\|", "%");