Regex.Escape

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

using System;
using System.Text.RegularExpressions;
class Program
{
static void Main()
{
string str = "a\nb";
Console.WriteLine(Regex.Escape(str));
// 输出: a\nb
}
}
posted @ 2014-02-25 15:27  wanshutao  阅读(2141)  评论(0编辑  收藏  举报