[英]Increment a string from numbers 0-9 to lowercase a-z to uppercase A-Z in C#
[英]Is there a way I can find out if a string in C# does not contain the numbers & characters 0-9 and A-Z?
我已经看过某种正则表达式测试,但是如何检查字符串是否不包含任何0-9数字或AZ字符?
您不需要正则表达式:
string s = ...
bool hasLetterOrDigit = s.Any(c => char.IsLetterOrDigit(c));
bool onlyLetterOrDigit = s.All(c => char.IsLetterOrDigit(c));
IsLetterOrDigit()
函数使用Unicode分类( MSDN )。
如果要精确控制:
string s = ...
string allowedChars = "abcdefABCDEF0123456789";
bool onlyAllowedChar = s.All(c => allowedChars.Contains(c));
使用正则表达式尝试
bool Exists=Regex.IsMatch(input, @"[^A-Z0-9]+");
就像是...
if ((Regex.IsMatch(value, "[^A-Z0-9]+")
{
//do something
}
编辑:更改为匹配Matt的建议。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.