Remove Special Characters - CSharp System

CSharp examples for System:String Strip

Description

Remove Special Characters

Demo Code


using System.Text;

public class Main{
        public static string RemoveSpecialCharacters(string str)
        {//w  w w .ja  v  a  2s  .  c  o  m
            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();
        }
}

Related Tutorials