我想检查输入的字符串长度是否在3到8个字符之间.以前我用过if condition它并且有效.但是当我从字符串中引入一些子字符串时,其中一个if statements不起作用.有人可以帮我理解原因.谢谢.
我的代码是
工作守则:
text = et.getText().toString();
l = text.length();
a = text.substring(0, 1);
if (l >=9) tv.setText("Invalid length!!! Please check your code");
if (l <= 2) tv.setText("Invalid length! Please check your code");
Run Code Online (Sandbox Code Playgroud)
在这里,第二项if statement doesnt工作.
text = et.getText().toString();
l = text.length();
a = text.substring(0, 1);
c = text.substring(1, 2);
d = text.substring(3, 4);
e = text.substring(4);
if (l >=9) tv.setText("Invalid length!!! Please check your code");
if (l <= 2) tv.setText("Invalid length! Please …Run Code Online (Sandbox Code Playgroud)