怎么判断一个字符串中是否包含特殊字符(!@#$%^&*()_+|这些).如果用正则表达式来判断该怎么写?

解决方案 »

  1.   

    感觉用正则,和用数组也没什么区别吧,弄个数组,用indexOf判断呗
      

  2.   

    string input = "A(!@#23R1$%C^&*G()_+|B";        MatchCollection matches=Regex.Matches(input,@"[\(!@\#\$%\^&\*\(\)_\+\|]");
                    if (matches.Count>0)
            {
                List<string> list=new List<string> ();
                foreach(Match m in matches)
                {
                    list.Add(m.Value);
                }
                Response.Write("存在非法字符"+string.Join(",",list.ToArray()));
            }