This is my string value:
string str = \"32 ab d32\";
And this list is my allowed characters:
var allowedCharacters = new List&l
Here is a simple but performant foreach solution:
Hashset lstAllowedCharacters = new Hashset{'a','b','c','2',' '};
var resultStrBuilder = new StringBuilder(srVariable.Length);
foreach (char c in srVariable)
{
if (lstAllowedCharacters.Contains(c))
{
resultStrBuilder.Append(c);
}
else
{
resultStrBuilder.Append(" ");
}
}
srVariable = resultStrBuilder.ToString();