Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/260.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何知道字符串长度是否包含指定数量的大写字母_C#_Discord.net - Fatal编程技术网

C# 如何知道字符串长度是否包含指定数量的大写字母

C# 如何知道字符串长度是否包含指定数量的大写字母,c#,discord.net,C#,Discord.net,我想知道一个字符串是否包含5到10之间的长度,同时,7到10个字母是大写的。其思想是检测用户发送的消息是否有70%-100%的上限 这就是我迄今为止所尝试的: bool IsMessageUpper(字符串输入) { if(input.Length.Equals(5char.isleter(c)&&char.IsUpper(c))) { 返回true; } 其他的 { 返回false; } } 您可以用这种方式重写您的方法 bool IsMessageUpper(string input) {

我想知道一个字符串是否包含5到10之间的长度,同时,7到10个字母是大写的。其思想是检测用户发送的消息是否有70%-100%的上限

这就是我迄今为止所尝试的:

bool IsMessageUpper(字符串输入)
{
if(input.Length.Equals(5char.isleter(c)&&char.IsUpper(c)))
{
返回true;
}
其他的
{
返回false;
}
}

您可以用这种方式重写您的方法

bool IsMessageUpper(string input)
{
    int x = input.Length;
    return x>=7 && x<= 10 && input.Count(char.IsUpper) >= 7;
}
bool IsMessageUpper(字符串输入)
{
int x=输入长度;
返回x>=7&&x=7;
}
您还可以添加一些安全检查来处理不必要的输入

bool IsMessageUpper(string input)
{
    int x = (input ?? "").Length;
    return x>=7 && x<= 10 && input.Count(char.IsUpper) >= 7;
}
bool IsMessageUpper(字符串输入)
{
INTX=(输入?)。长度;
返回x>=7&&x=7;
}

不要取前七个字符,看它们都是大写字母,而是计算大写字母的数量
input.Count(Char.IsUpper)
一个包含7个大写字符的字符串怎么能有5个长度?逻辑中有些错误。请删除
x>=5
检查,它什么也没做,或者如果要防止调用
输入,请将其更改为
x>=7
。计数过多。