Skip to main content
1 of 2
Vadim Ovchinnikov
  • 1.3k
  • 2
  • 12
  • 25

I'd use Regex for this.

public static class StringCleaner
{
    private const Pattern = @"[^a-zA-Z0-9 \#\\\'\(\)\+\,\-\.\/\[\]_`\{\|\}\~\:\?@]";

    public static string Clean(string address, string replacement = "") =>
            Regex.Replace(address, Pattern, replacement);
}
Vadim Ovchinnikov
  • 1.3k
  • 2
  • 12
  • 25