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);
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With