Why is the following algorithm not halting for me? (str is the string I am searching in, findStr is the string I am trying to find)
String str = \"helloslkhe
Here it is, wrapped up in a nice and reusable method:
public static int count(String text, String find) { int index = 0, count = 0, length = find.length(); while( (index = text.indexOf(find, index)) != -1 ) { index += length; count++; } return count; }