LINQ will do the job nicely:
var newList = list.Select(s => '#' + s.Split('#')[1] + '#').ToList();
Or, if you prefer query expressions:
var newList = (from s in list
select '#' + s.Split('#')[1] + '#').ToList();
Alternatively, you can use regular expressions as suggested with Botz3000 and combine them with LINQ:
var newList = new List(
from match in list.Select(s => Regex.Match(s, "#[^#]+#"))
where match.Success
select match.Captures[0].Value
);
user142019
source
share