Count occurrences of a substring: Difference between revisions
Content added Content deleted
(→{{header|RPL}}: simple, idiomatic version) |
|||
Line 3,299: | Line 3,299: | ||
=={{header|RPL}}== |
=={{header|RPL}}== |
||
{{works with|Halcyon Calc|4.2.7}} |
{{works with|Halcyon Calc|4.2.7}} |
||
≪ |
≪ DUP SIZE 1 - → str substr subsize |
||
≪ |
≪ 0 |
||
1 str SIZE subsize + '''FOR''' j |
|||
str j DUP subsize + SUB |
|||
''' |
'''IF''' substr == '''THEN''' |
||
1 + |
|||
j subsize + 'j' STO |
|||
'''END''' |
'''END''' |
||
'''NEXT''' |
|||
≫ ≫ '<span style="color:blue">CNTSUB</span>' STO |
|||
'''ELSE''' DROP2 -1 '''END''' |
|||
≫ ≫ ''''CNTSUB'''' STO |
|||
"the three truths" <span style="color:blue">CNTSUB</span> |
|||
"ababababab" <span style="color:blue">CNTSUB</span> |
|||
{{out}} |
|||
<pre> |
|||
2: 3 |
|||
1: 2 |
|||
</pre> |
|||
=={{header|Ruby}}== |
=={{header|Ruby}}== |