Join list of string to comma separated and enclosed in single quotes

后端 未结 6 1162
旧时难觅i
旧时难觅i 2021-02-03 19:41
List test = new List();
test.Add(\"test\'s\");
test.Add(\"test\");
test.Add(\"test\'s more\");
string s = string.Format(\"\'{0}\'\", string.J         


        
6条回答
  •  南方客
    南方客 (楼主)
    2021-02-03 19:57

    Try this:

    string s = string.Join(",", test.Select(x => string.Format("'{0}'", x.Replace("'", "''"))));
    

    By the way, there's no apostrophe in "tests" - apostrophes aren't used for plurals.

提交回复
热议问题