3

This is my code and I want single quote before and after.

char[] charsToTrim = { '\\' };
selectedITeration += (lis.Text.Trim(charsToTrim) + ",").Replace(@"\", @"\\");

Output:

    \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

I want something like this:

'MRI_SCRUM_GIT\\AS-Automation',
'MRI_SCRUM_GIT\\Pluse Pheonix',
'MRI_SCRUM_GIT\\Pluse Pheonix\\Sprint 1',
'MRI_SCRUM_GIT\\Pluse Pheonix\\Sprint 10'

2 Answers2

4

try this

selectedITeration +=
   String.Format("'{0}'", (lis.Text.Trim(charsToTrim) + ",").Replace(@"\", @"\\"));

or C# 6.0 (string inerpolation)

selectedITeration += $"'{(lis.Text.Trim(charsToTrim) + ",").Replace(@"\", @"\\")}'";

Just for FYI : Does C# 6.0 work for .NET 4.0?

Pranay Rana
  • 175,020
  • 35
  • 237
  • 263
  • String interpolation doesn't depend on the .NET Framework - but on the version of the C# compiler - has to be v6 or higher – marc_s Apr 02 '18 at 07:14
  • 1
    @marc_s - updated and thanks , i thought better to put framework , most of the people got confuse with C# version and framework version , yes it language feature – Pranay Rana Apr 02 '18 at 07:16
  • could u modify ur answer i have changed Question little bit (not needed the iteration now) @PranayRana –  Apr 02 '18 at 09:21
  • @nikhiljain - dont see any update in question ...and not getting you at all ...no iteration means you have long string ?? – Pranay Rana Apr 02 '18 at 09:23
  • @nikhiljain - what is change in it , i see same , and not much detail – Pranay Rana Apr 02 '18 at 09:28
  • don't want the Iteration part \MRI_SCRUM_GIT\\Iteration\\Pluse Pheonix\Sprint 10 should become MRI_SCRUM_GIT\\Pluse Pheonix\\Sprint 10 @PranayRana –  Apr 02 '18 at 09:39
  • @PranayRana got it boss ? –  Apr 02 '18 at 10:13
  • @nikhiljain - remove iteration just do` (lis.Text.Trim(charsToTrim) + ",").Replace("Iteration\\","").Replace(@"\", @"\\")` – Pranay Rana Apr 02 '18 at 10:15
1

What is so difficult in that:

selectedITeration += ("'" + lis.Text.Trim(charsToTrim) + "',").Replace(@"\", @"\\");
Sadique
  • 22,572
  • 7
  • 65
  • 91
  • could u modify ur answer i have changed Question little bit (not needed the iteration now) –  Apr 02 '18 at 09:15