Advertisement
AliShahbaz

Remove special characters from string

Nov 19th, 2013
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.43 KB | None | 0 0
  1. public static string RemoveSpecialCharacters(string str)
  2.         {
  3.             StringBuilder sb = new StringBuilder();
  4.             foreach (char c in str)
  5.             {
  6.                 if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || c == '.' || c == '_' || c == '-')
  7.                 {
  8.                     sb.Append(c);
  9.                 }
  10.             }
  11.             return sb.ToString();
  12.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement