如何将此字符串列表转换为用引号括起来的逗号分隔值,而无需任何转义字符?
{"apple", "berry", "cherry"} => well, ""apple", "berry", "cherry""
如果我理解正确的话,
"\"" + String.Join("\", \"", new string[]{"apple","berry","cherry"}) + "\"";
或者,或者,
String.Format("\"{0}\"", String.Join("\", \"", new string[] {"apple","berry","cherry"}));
阅读更多关于System.String.Join(...)。
希望这能完成工作
var ar = new []{ "apple", "berry", "cherry" };
var separator = "\",\"";
var enclosingTag = "\"";
Console.WriteLine ( enclosingTag + String.Join(separator, ar) + enclosingTag );
如果您使用 C#:
using System;
string[] arr = new string[] { "apple", "berry", "cherry" };
string sep = "\",\"";
string enclosure = "\"";
string result = enclosure + String.Join(sep, arr) + enclosure;