Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert List<string> into String of Comma Separated Quotes from List [duplicate]

Tags:

c#

I am trying to convert a list of strings into a comma separated with quotes variable,I can only join them as comma separated but can't put quotes around each of the entries in the list..can anyone provide guidance on how to fix it?

INPUT:

variants = 

[
    "CI_ABC1234.LA.0.1-03391-STD.INT-32",
    "CI_ABC1234.LA.0.1-33103-STD.INT-32"
  ]

EXPECTED OUTPUT:

('CI_ABC1234.LA.0.1-03391-STD.INT-32','CI_ABC1234.LA.0.1-33103-STD.INT-32')

CODE:-

string variants_str = String.Join(",", variants); 
like image 792
user3508811 Avatar asked Mar 09 '23 04:03

user3508811


1 Answers

LINQ's Select() extension method allows to convert each item in a collection:

string variants_str = String.Join(",", variants.Select(s => "'" + s + "'")); 

Demo: https://dotnetfiddle.net/I37xr6

like image 145
Dmitry Egorov Avatar answered May 10 '23 00:05

Dmitry Egorov