If you want to use LINQ, you can use Select, ToArray and the String(char[]) constructor like this:
var result = query.ToList();
foreach (var x in result)
{
x.SomeProperty =
new string(x.SomeProperty
.Select(c => (c == 'X' || ... || c == ' ') ? '_' : c)
.ToArray());
}
Note that LINQ is not intended to be used to cause side-effects, but to create new enumerables from existing enumerables. So a foreach
loop is better here.
But why not simply a chain of Replace calls?
var result = query.ToList();
foreach (var x in result)
{
x.SomeProperty = x.SomeProperty
.Replace('X', '_')
.Replace('Y', '_')
.Replace('Z', '_')
.Replace(' ', '_');
}
Or are you trying to replace a single character with a sequence of characters?
Then use the String.Replace overload that takes two strings:
var result = query.ToList();
foreach (var x in result)
{
x.SomeProperty = x.SomeProperty.Replace(" ", "ABC");
}