我目前有一个方法,应该采取两个字符串,然后检查一个字符串是否作为其他字符串存在.它不会检查两种方式,因此我将字符串传递给方法的方式决定了在另一方中查找的字符串.
目前我收到stackoverflow错误.
public boolean checkMatch(String text, String regex, int i){
int regexL = regex.length();
if(i == regexL){
return true;
}
System.out.println(text.charAt(i) + " " + regex.charAt(i));
if(text.charAt(i) == regex.charAt(i)){
return checkMatch(text, regex, i++);
}
else if(text.charAt(i) != regex.charAt(i)){
if(text.substring(1) == ""){
return false;
}
else if(text.substring(1) != ""){
return checkMatch(text.substring(1), regex, 0);
}
}
return false;
}
Run Code Online (Sandbox Code Playgroud)
我正在使用我的名字作为例子进行测试.
@Test public void test_52() {
assertEquals(true, checkMatch("Samual", "mu", 0));
}
Run Code Online (Sandbox Code Playgroud)
它溢出后,控制台看起来像这样.
S m
上午
毫米
毫米
毫米
等等
我哪里错了?我错了吗?堆栈跟踪显示它似乎被抓到了这一行.
return …Run Code Online (Sandbox Code Playgroud)