Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c# join string comma delimited, but double quote all values inside

Tags:

c#

I have a string list

new List<string> { "One", "Two", "Three", "Four", "Five", "Six" }

And I want to have a string with exact this content (including double quotes)

"One", "Two", "Three", "Four", "Five", "Six"

Because will write a text file that will be a array[] = { my_string }

I tried this with no success

var joinedNames = fields.Aggregate((a, b) => "\"" + a + ", " + b + "\"");

Little LINQ help will be greatly appreciate :)

like image 229
orfruit Avatar asked May 03 '17 16:05

orfruit


1 Answers

var joinedNames = "\"" + string.Join("\", \"", fields) + "\"";
like image 140
Joel Coehoorn Avatar answered Sep 17 '22 20:09

Joel Coehoorn