java - StackOverflow when checking if one string is contained in another -


i have method supposed take 2 strings , check if 1 string exists substring in other. doesn't check both ways way in pass strings method determines string looked in other.

currently getting stackoverflow error.

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;  } 

i running test using first name example.

@test public void test_52() {     assertequals(true, checkmatch("samual", "mu", 0)); } 

the console looks after overflows.

s m

a m

m m

m m

m m

etc

where going wrong? iterating wrong? stack trace shows seems getting caught on line.

return checkmatch(text, regex, i++); 

but defect point point of failure. sorry wall of text , code.

i don't know if rest correct, here 1 error: i++increments i after evaluated. call function same value every time. mean ++i.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -