Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to turn array into quote and comma delimited string for sql?

Tags:

c#

linq

I have a list I want to pass into SQL but they must be single quote and comma delimited.

So List = a b c

But I need a string = 'a','b','c'

How can I accomplish this in a concise manner?

Something like this I think but can't see within LINQ how to add to beginning and end:

String.Join(",", arr.Select(p => p.ToString()).ToArray())
like image 327
Mark McGown Avatar asked Jan 29 '23 00:01

Mark McGown


1 Answers

Maybe something along the lines of:

String.Join(",", arr.Select(p=> "'" + p.ToString() + "'").ToArray());

// or is p already a string

String.Join(",", arr.Select(p => "'" + p + "'").ToArray());
like image 95
StaticBeagle Avatar answered Jan 30 '23 14:01

StaticBeagle