Anonymous user
Count occurrences of a substring: Difference between revisions
m
→{{header|Java}}: Typos
m (Clarify that the highest number of matches should be shown. Existing examples are fine.) |
m (→{{header|Java}}: Typos) |
||
Line 38:
</pre>
=={{header|Java}}==
This method
<lang java>import java.util.regex.Pattern;
Line 47:
do{
str = newStr;
newStr = str.replaceFirst(Pattern.quote(subStr), "");//attempt a
ans++;//count it
}while(!str.equals(newStr));
Line 63:
2
2</pre>
=={{header|Perl}}==
<lang perl>sub countSubstring {
|