This is my string value:
string str = \"32 ab d32\";
And this list is my allowed characters:
var allowedCharacters = new List&l
Try this:
string srVariable = "32 ab d32";
List lstAllowedCharacters = new List { "a", "b", "c", "2", " " };
srVariable = Regex.Replace(srVariable, "[^" + Regex.Escape(string.Join("", lstAllowedCharacters) + "]"), delegate(Match m)
{
if (!m.Success) { return m.Value; }
return " ";
});
Console.WriteLine(srVariable);