如何在 C# 控制台应用程序中打印双引号 (")
How to print double quotes (") in c# console application
我知道 c# 只打印双引号内的数据:
Console.WriteLine("These two double quotes are removed when i am printed");`
它在控制台中的输出将是:
These two double quotes are removed when i am printed
但是我想在控制台上打印的是带双引号的相同内容:
"These two double quotes are removed when i am printed"
我该怎么做。我正在尝试这样做,因为我必须将此输出写入双引号有意义的文件。
您需要使用 \
:
转义字符
Console.WriteLine("\"These two semi colons are removed when i am printed\"");
此外,您所指的字符 ("
) 不是分号而是引号。分号是 ;
.
只需添加 \
。请参阅 String literals 文章
Console.WriteLine("\"These two semi colons are removed when i am printed\"");
我知道 c# 只打印双引号内的数据:
Console.WriteLine("These two double quotes are removed when i am printed");`
它在控制台中的输出将是:
These two double quotes are removed when i am printed
但是我想在控制台上打印的是带双引号的相同内容:
"These two double quotes are removed when i am printed"
我该怎么做。我正在尝试这样做,因为我必须将此输出写入双引号有意义的文件。
您需要使用 \
:
Console.WriteLine("\"These two semi colons are removed when i am printed\"");
此外,您所指的字符 ("
) 不是分号而是引号。分号是 ;
.
只需添加 \
。请参阅 String literals 文章
Console.WriteLine("\"These two semi colons are removed when i am printed\"");