Last active
May 19, 2017 09:49
-
-
Save baoanhng/0c26e858d7516d443b482433fbeeccc2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static int subStrCount(String string, String substr) { | |
int count = 0; | |
int lastIndex = 0; | |
while ( (lastIndex = string.indexOf(substr, lastIndex) + 1) > 0 ) { | |
count++; | |
} | |
return count; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment