How to find whether a string contains any of the special characters?

后端 未结 10 1327
春和景丽
春和景丽 2020-12-10 01:43

I want to find whether a string contains any of the special characters like !,@,#,$,%,^,&,*,(,)....etc.

How can I do that without looping thorugh all the charact

10条回答
  •  盖世英雄少女心
    2020-12-10 01:54

    Also...

    foreach (char character in "some*!@#@!#string")
            {
                if(!Char.IsLetterOrDigit(character))
                {
                    //It is a special character.
                }
            }
    

提交回复
热议问题