Created
September 9, 2011 12:51
-
-
Save musicm122/1206121 to your computer and use it in GitHub Desktop.
Efficient Replace Special char method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static string RemoveSpecialCharacters(string str) | |
{ | |
int idx = 0; | |
char[] chars = new char[str.Length]; | |
foreach (char c in str) | |
{ | |
if ((c >= '0' && c <= '9') | |
|| (c >= 'A' && c <= 'Z') | |
|| (c >= 'a' && c <= 'z') | |
|| (c == '.') || (c == '_')) | |
{ | |
chars[idx++] = c; | |
} | |
} | |
return new string(chars, 0, idx); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See
http://sixlettervariable.blogspot.com/search/label/c%23
http://stackoverflow.com/questions/1120198/most-efficient-way-to-remove-special-characters-from-string/1120407#1120407