
Untitled
By: a guest on
May 8th, 2012 | syntax:
None | size: 0.92 KB | hits: 17 | expires: Never
remove quote from list<string> using linq
List<string> strings = new List<string>();
strings.Add("'Value1");
strings.Add("'Values2 This 2nd ' should stay");
strings.ForEach(s => s = s.TrimStart('''));
List<string> strings = new List<string>();
strings.Add("'Value1");
strings.Add("'Values2 This 2nd ' should stay");
Console.WriteLine("Before:");
foreach (string s in strings) {
Console.WriteLine(s);
}
strings.ForEach(s => s = s.TrimStart('''));
Console.WriteLine();
Console.WriteLine("After:");
foreach (string s in strings) {
Console.WriteLine(s);
}
Console.ReadKey();
Before:
'Value1
'Values2 This 2nd ' should stay
After:
'Value1
'Values2 This 2nd ' should stay
strings = strings.Select(x => x.StartsWith("'") ? x.Substring(1) : x).ToList();
strings.Select(s => s.StartsWith("'") ? s.Substring(1) : s);
var result = strings.Select(s => s.TrimStart('''));
strings.Add("'Value1".TrimStart('''));