Last Updated: February 25, 2016
·
316
· marcuso

Function for removing unwanted characters

Only approved characters in the string OKChars.

private string Clean(string text) {
string OKChars="abcdefghijklmnopqrstuvwxyzåäöABCDEFGHIJKLMNOPQRSTUVWXYZÅÄÖ1234567890 _-";
    StringBuilder sb = new StringBuilder();
    foreach (char c in text.Trim().ToCharArray())
if (OKChars.Contains(c.ToString()))
             sb.Append(c);
return sb.ToString();
}