这是我的代码,我想要前后单引号. char[] charsToTrim = { '\\' };selectedITeration += (lis.Text.Trim(charsToTrim) + ",").Replace(@"\", @"\\"); 输出: \MRI_SCRUM_GIT\\Iteration\\AS-Automation,\MRI_SCRUM_GIT\\Iteration\\Pluse Phe
char[] charsToTrim = { '\\' }; selectedITeration += (lis.Text.Trim(charsToTrim) + ",").Replace(@"\", @"\\");
输出:
\MRI_SCRUM_GIT\\Iteration\\AS-Automation, \MRI_SCRUM_GIT\\Iteration\\Pluse Pheonix, \MRI_SCRUM_GIT\\Iteration\\Pluse Pheonix\Sprint 1, \MRI_SCRUM_GIT\\Iteration\\Pluse Pheonix\Sprint 10
我想要这样的东西:
'MRI_SCRUM_GIT\\AS-Automation', 'MRI_SCRUM_GIT\\Pluse Pheonix', 'MRI_SCRUM_GIT\\Pluse Pheonix\\Sprint 1', 'MRI_SCRUM_GIT\\Pluse Pheonix\\Sprint 10'试试这个
selectedITeration += String.Format("'{0}'", (lis.Text.Trim(charsToTrim) + ",").Replace(@"\", @"\\"));
或C#6.0(string inerpolation)
selectedITeration += $"'{(lis.Text.Trim(charsToTrim) + ",").Replace(@"\", @"\\")}'";
仅供参考:Does C# 6.0 work for .NET 4.0?