First time poster and a programming newbie so go easy on me! Just working on a little challenge given to me that required a method to check if a substring (aSub
) could be found within a string (aString
). This is what I wrote but it always returns false
unless aSub == aString
, then it will return true
. I'm sure this will be a facepalm to a lot of you but I lack the experience to see exactly where the fault is! Thanks guys!
/**
*
*/
public boolean stringChecker(String aString, String aSub)
{
boolean foundIt = false;
int beginIndex = 0;
int endIndex = aSub.length();
while((foundIt == false) && (endIndex <= aString.length()))
{
if(aSub != aString.substring(beginIndex, endIndex))
{
beginIndex = beginIndex + 1;
endIndex = endIndex + 1;
}
else
{
foundIt = true;
}
}
return foundIt;
}