[英]formatting string in C#
如何将此字符串列表转换为用引号引起来的逗号分隔值而没有任何转义符?
{"apple", "berry", "cherry"} => well, ""apple", "berry", "cherry""
If I understood you correctly, 如果我对你的理解正确,
"\"" + String.Join("\", \"", new string[]{"apple","berry","cherry"}) + "\"";
or, alternatively, 或者,
String.Format("\"{0}\"", String.Join("\", \"", new string[] {"apple","berry","cherry"}));
Read more on System.String.Join(...) . 阅读更多有关System.String.Join(...)的内容 。
Hope this will do the job 希望这能做好
var ar = new []{ "apple", "berry", "cherry" };
var separator = "\",\"";
var enclosingTag = "\"";
Console.WriteLine ( enclosingTag + String.Join(separator, ar) + enclosingTag );
If you are using C#: 如果您使用的是C#:
using System;
string[] arr = new string[] { "apple", "berry", "cherry" };
string sep = "\",\"";
string enclosure = "\"";
string result = enclosure + String.Join(sep, arr) + enclosure;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.