Count occurrences of a substring: Difference between revisions
Content deleted Content added
→{{header|Perl}}: Added PureBasic |
→{{header|Perl}}: don't apologize for not handling metachars when you can just handle 'em :) |
||
Line 37:
=={{header|Perl}}==
<lang perl>sub countSubstring {
my
my $sub = quotemeta(shift);
my $count = () = $str =~ /$sub/g;
return $count;
Line 47:
print countSubstring("the three truths","th"), "\n";
print countSubstring("ababababab","abab"), "\n";</lang>
=={{header|PureBasic}}==
<lang PureBasic>a = CountString("the three truths","th")
|