我正在尝试找出最长有效子字符串的长度。有效的子字符串是包含至少 1 个大写字母且没有数字的子字符串。我的代码不起作用有人可以帮忙谢谢。
class Program
{
public static void Main(string[] args)
{
string S = "a02caa3ThisIsValid1bC2a";
Console.WriteLine("The longest valid substring is {0}", solution(S));
Console.ReadKey();
}
public static int solution(string S)
{
char[] stringarray = S.ToCharArray();
int slength = S.Length;
int result = 0;
// string resultstring = "";
for (int i = 0; i < slength; i++)
{
char Z = stringarray[i];
if(char.IsUpper(Z) || char.IsLower(Z) || !char.IsDigit(Z))
{
while (char.IsUpper(Z) || char.IsLower(Z) && !char.IsDigit(Z))
{
result += 1;
// resultstring = result.ToString();
}
}
}
return result;
}
}
ibeautiful
LEATH
慕码人8056858
相关分类