检查天气字符串包含数字特殊字符等 [英] Check weather string Contain numbers special Char etc
本文介绍了检查天气字符串包含数字特殊字符等的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何检查天气字符串包含特殊字符等数字
how can check weather a string Contain numbers special Char etc
推荐答案
^ ]看起来是个不错的选择.
IndexOfAny()
[^] looks like a good choice.
Richard MacCutchan 很好.
或者,如果您要检查字符串是否包含特定类别的字符,例如Punctuation
或Numbers
等,则可以考虑使用System.Text.RegularExpressions.Regex
类,如下所示:
The Solution 1 given by Richard MacCutchan is very good.
As an alternative if you want to check whether the string contains a particular category of characters sayPunctuation
orNumbers
etc., then theSystem.Text.RegularExpressions.Regex
class can be considered to test as shown below:
string text = "Is this text, contains special chars?";
//The Regex pattern matches if atleast one character of the
//alternatives is found \p{P} Unicode punctuation category
//\p{N} Unicode numbers category
if(System.Text.RegularExpressions.Regex.IsMatch(text,@"\p{P}|\p{N}"))
Console.WriteLine ("Contains special chars");
else
Console.WriteLine ("Does not contain special chars");
//Output
//Contains special chars
您可能会请尝试以下,
You might try below,
class Program
{
static void Main(string[] args)
{
string randomCharacters = "HelloWorld2090!!!@#
这篇关于检查天气字符串包含数字特殊字符等的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文