【发布时间】:2011-08-03 23:44:41
【问题描述】:
List<string> test = new List<string>();
test.Add("test's");
test.Add("test");
test.Add("test's more");
string s = string.Format("'{0}'", string.Join("','", test));
现在 s 是 'test's','test','test's more'
但我需要用 2 个单引号替换内引号
像这样:'test''s','test','test''s more'
更新:我让它按如下方式工作,但如果可能的话,我更喜欢更清洁的方式。
string s = string.Format("`{0}`", string.Join("`,`", test)).Replace("'", "''").Replace("`", "'");
【问题讨论】:
标签: c# string c#-4.0 string-formatting