Count occurrences of a substring: Difference between revisions
Content added Content deleted
Simple9371 (talk | contribs) (Add Batch File) |
Simple9371 (talk | contribs) (My first ever edit in an Ubuntu Virtual Machine) |
||
Line 1,827: | Line 1,827: | ||
2 occurence(s) of cat inside catapultcatalog</pre> |
2 occurence(s) of cat inside catapultcatalog</pre> |
||
=={{header|UNIX Shell}}== |
|||
{{works with|Bash}} |
|||
<lang bash>#!/bin/bash |
|||
function countString(){ |
|||
input=$1 |
|||
cnt=0 |
|||
until [ "${input/$2/}" == "$input" ]; do |
|||
input=${input/$2/} |
|||
let cnt+=1 |
|||
done |
|||
echo $cnt |
|||
} |
|||
countString "the three truths" "th" |
|||
countString "ababababab" "abab"</lang> |
|||
{{Out}} |
|||
<pre>3 |
|||
2</pre> |
|||
=={{header|VBA}}== |
=={{header|VBA}}== |