简体   繁体   English

如何检测字符串中的特殊字符和数字?

[英]How to detect special characters and numbers in a string?

Does anyone have an idea on how to detect special characters in a string via an if statement?有没有人知道如何通过 if 语句检测字符串中的特殊字符?

I need the output to look something like this:我需要输出看起来像这样:

Enter Name: Johnson!
INVALID INPUT TRY AGAIN.
Enter Name: Johnson
ACCEPTED INPUT.

Is there any way to do that with only using.System ?有没有办法只使用 using.System 做到这一点?

As your question is not very clear, try this, if you want to check one of some specified characters are exist in your string input由于您的问题不是很清楚,请尝试此操作,如果您想检查字符串input是否存在某些指定字符之一

var specialChars = new[] {"!", ":", ",", "/", "1"}; //add some or more characters or numbers as into this string array
var result = specialChars.Any(input.Contains)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM