C# 格式在字符串中存储双引号
我要表示以下字符串:C# 格式在字符串中存储双引号,c#,string,C#,String,我要表示以下字符串: aaaa,23,"something inside double quotes", 99, 8, 7 我正在考虑使用String.Format: StringBuilder.AppendLine(string.Format("{0},{1},{2},{3},{4},{5}", item.one, item.two, item.three, item.four, item.five, item.six)); 我需要用双引号将第三个参数{2}括起来 您应该在
aaaa,23,"something inside double quotes", 99, 8, 7
我正在考虑使用String.Format
:
StringBuilder.AppendLine(string.Format("{0},{1},{2},{3},{4},{5}",
item.one, item.two, item.three, item.four, item.five, item.six));
我需要用双引号将第三个参数
{2}
括起来 您应该在qoutes之前添加\
:
string.Format("{0}, {1}, \"{2}\", {3}, {4}, {5}", ...);
stringbuilder.AppendLine(string.Format("{0},{1},\"{2}\",{3},{4},{5}", item.one, item.two, item.three, item.four, item.five, item.six));
您可以这样做:
string.Format("{0},{1},\"{2}\",{3},{4},{5}"
, item.one
, item.two
, item.three
, item.four
, item.five
, item.six);
这里有一个很好的链接,您可以从中了解更多信息:您可以放置
\
符号以指示转义序列,后跟保留字符(通常是\n、\0、\t、\r、\”等)相关: