0

如何将此字符串列表转换为用引号括起来的逗号分隔值,而无需任何转义字符?

{"apple", "berry", "cherry"} => well, ""apple", "berry", "cherry""
4

3 回答 3

1

如果我理解正确的话,

"\"" + String.Join("\", \"", new string[]{"apple","berry","cherry"}) + "\"";

或者,或者,

String.Format("\"{0}\"", String.Join("\", \"", new string[] {"apple","berry","cherry"}));

阅读更多关于System.String.Join(...)

于 2012-08-18T03:18:52.300 回答
0

希望这能完成工作

var ar = new []{ "apple", "berry", "cherry" };
var separator = "\",\"";
var enclosingTag = "\"";
Console.WriteLine ( enclosingTag + String.Join(separator, ar) + enclosingTag );
于 2012-08-18T03:19:58.837 回答
0

如果您使用 C#:

using System;
string[] arr = new string[] { "apple", "berry", "cherry" };
string sep = "\",\"";
string enclosure = "\"";
string result = enclosure + String.Join(sep, arr) + enclosure;
于 2012-08-18T05:16:05.103 回答