当前位置 : 主页 > 编程语言 > c++ >

如何在字符串c#asp.net之前和之后添加单引号?

来源:互联网 收集:自由互联 发布时间:2021-06-23
这是我的代码,我想要前后单引号. 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?

网友评论