0

How can I convert this list of strings to comma separated value enclosed within quotes without any escape characters?

{"apple", "berry", "cherry"} => well, ""apple", "berry", "cherry""
2
  • This is now completely useless. Commented Aug 18, 2012 at 4:03
  • What language is this? C#? Javascript, C++? Commented Aug 18, 2012 at 5:18

3 Answers 3

1

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(...).

Sign up to request clarification or add additional context in comments.

Comments

0

Hope this will do the job

var ar = new []{ "apple", "berry", "cherry" };
var separator = "\",\"";
var enclosingTag = "\"";
Console.WriteLine ( enclosingTag + String.Join(separator, ar) + enclosingTag );

Comments

0

If you are using C#:

using System;
string[] arr = new string[] { "apple", "berry", "cherry" };
string sep = "\",\"";
string enclosure = "\"";
string result = enclosure + String.Join(sep, arr) + enclosure;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.