C# String.Format 在字符串中存储双引号
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15610091/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
String.Format store double quotes inside string
提问by user1765862
I want to represent the following string:
我想代表以下字符串:
aaaa,23,"something inside double quotes", 99, 8, 7
I was thinking to do this using String.Format
:
我正在考虑使用String.Format
以下方法执行此操作:
StringBuilder.AppendLine(string.Format("{0},{1},{2},{3},{4},{5}",
item.one, item.two, item.three, item.four, item.five, item.six));
I need to wrap third argument {2}
with double quotes.
我需要{2}
用双引号包裹第三个参数。
回答by acrilige
string.Format("{0}, {1}, \"{2}\", {3}, {4}, {5}", ...);
回答by evgenyl
You should add \
before qoutes:
您应该\
在 qoutes 之前添加:
stringbuilder.AppendLine(string.Format("{0},{1},\"{2}\",{3},{4},{5}", item.one, item.two, item.three, item.four, item.five, item.six));
回答by Jonas W
You can do like this :
你可以这样做:
string.Format("{0},{1},\"{2}\",{3},{4},{5}"
, item.one
, item.two
, item.three
, item.four
, item.five
, item.six);
Here is a good link where you can read more about this : http://msdn.microsoft.com/en-us/library/267k4fw5.aspx
这是一个很好的链接,您可以在其中阅读更多相关信息:http: //msdn.microsoft.com/en-us/library/267k4fw5.aspx
回答by xiriusly
you can put \
symbol to indicate escape sequence followed by a reserved characters (usually \n, \0, \t, \r, \", etc)
您可以将\
符号表示转义序列,后跟保留字符(通常为 \n、\0、\t、\r、\" 等)