Reputation: 3256
I have list of names:
IEnumerable<Name> names;
names = n.GetNames(abc);
It gets list like: Ken, John, Sam,... I want it to show like this: 'Ken', 'John', 'Sam',...
I tried this:
string s = string.Join("',", names);
but it gives result like:
Ken', John', Sam',...
Is there a way to add "'" in front of these names in single line of code?
Upvotes: 2
Views: 414
Reputation: 190942
Try this.
string s = string.Join(",", names.Select(s => string.Format("'{0}'", s)).ToArray());
Upvotes: 3
Reputation: 5767
I think you were almost there:
string s = "'" + string.Join("','", names) + "'";
Upvotes: 3