Skip to content

Instantly share code, notes, and snippets.

@chuongmep
Created June 8, 2023 08:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chuongmep/0bc2c6399969e92a227cfd33103582a4 to your computer and use it in GitHub Desktop.
Save chuongmep/0bc2c6399969e92a227cfd33103582a4 to your computer and use it in GitHub Desktop.
public string RemoveSpecialCharacters( string str)
{
StringBuilder sb = new StringBuilder();
foreach (char c in str)
{
if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') ||
(c >= 'a' && c <= 'z') || c == '_' || c == '-' || c == '.' || c==' ')
{
sb.Append(c);
}
}
return sb.ToString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment