var a = "asdfgh\r";
Console.WriteLine(a.Contains(@"\r"));
var b = a.Replace(@"\r","").Replace(@"\n","");
var c = a.Replace("\r","").Replace("\n","");
Console.WriteLine(a);
Console.WriteLine(b);
Console.WriteLine(c);
“b”和“c”打印相同的字符串,“a”打印假,
我试图将 \r 和 \n 替换为空字符,所以首先我尝试了下面的代码,“\r”和“\n”中有一个反斜杠,所以我决定在它们之前使用“@”;
var b = a.Replace(@"\r","").Replace(@"\n","")
但这没有用,
var c = a.Replace("\r","").Replace("\n","");
这行得通,所以我很困惑什么时候应该使用“@”字符?