c# - 检查字符串是否有大写、小写和数字

标签 c# string if-statement

我想检查我的字符串是否有大小写和数字

string myString = "Hello123";

if (myString haveUppercase && myString haveLowerCase && myString haveNumber)
{
    this.hide();
}
else
{
    MessageBox.Show("Error!");
}

最佳答案

您可以将 char 的方法与 LINQ 一起使用:

if (myString.Any(char.IsUpper) &&
    myString.Any(char.IsLower) &&
    myString.Any(char.IsDigit))

关于c# - 检查字符串是否有大写、小写和数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27402126/

相关文章:

c# - 在多个订阅者的情况下,委托(delegate)如何知道调用哪个函数

c# - gridview 排序不适用于数字

c# - Redis IOException : "Existing connection forcibly closed by remote host" using ServiceStack C# client 错误

c# - 自动实现属性的代码契约(Contract)

SQL Server : check if variable is Empty or NULL for WHERE clause

python - 找到最小窗口子串

string - 在 Julia 中将变量名保存为字符串

string - ASCII 字符串到 MATLAB 中的二进制向量?

c# - 此代码立即将文本框更改为红色。我想要它,点击按钮,然后点击红色,然后再次点击绿色

c - 为什么这个段错误(核心转储)??? int main (int argc, char *argv[])