Well, there are many different utilities for this, for example. Apache Commons Lang String Utils
but in the end, he has to iterate over the string in order to read the events anyway.
Please also note that the countMatches method mentioned above has the following signature, therefore it will work under substrings as well.
public static int countMatches(String str, String sub)
Source for this (from here ):
public static int countMatches(String str, String sub) { if (isEmpty(str) || isEmpty(sub)) { return 0; } int count = 0; int idx = 0; while ((idx = str.indexOf(sub, idx)) != -1) { count++; idx += sub.length(); } return count; }
I was curious if they repeat the line or use Regex.
Casey May 23 '11 at 17:34 2011-05-23 17:34
source share