Regex.Escape

C# 字符串变量str 的值为"a
b"
如果直接输出显示的话,就成了:
a
b
需要输出显示为:a b
问,怎么办?千万别告诉我定义: str=@"a b",因为str的值不是我定义的

using System;
using System.Text.RegularExpressions;
class Program
{
static void Main()
{
string str = "a b";
Console.WriteLine(Regex.Escape(str));
// 输出: a b
}
}
原文地址:https://www.cnblogs.com/wanshutao/p/3566850.html