Replace Desired Charecter in String

Following is The function ,Use to replace the special Charecters in String by "_". 


 protected static string replaceBadChars(string input)  
     {  
       StringBuilder sb = new StringBuilder(input);  
       string[] chars = new string[27] { "%", " ", "&", "!", "`", "$", "*", "(", ")",  
         "{", "}", "[", "]", "/", "\\", "|", ";", "'", "\"", "<", ">", "?", "+", "#", "=", ".", "-" };  
       foreach (string st in chars)  
       {  
         sb.Replace(st, "_");  
       }  
       return sb.ToString();  
     }  

No comments:

Post a Comment