Count occurrences of a substring: Difference between revisions
Content added Content deleted
(Count occurrences of a substring in BASIC256 and Yabasic) |
(Count occurrences of a substring in True BASIC) |
||
Line 591: | Line 591: | ||
160 LET I=I+LEN U$ |
160 LET I=I+LEN U$ |
||
170 GOTO 130</lang> |
170 GOTO 130</lang> |
||
==={{header|True BASIC}}=== |
|||
{{trans|QBasic}} |
|||
<lang qbasic>FUNCTION countsubstring(where$, what$) |
|||
LET c = 0 |
|||
LET s = 1-LEN(what$) |
|||
DO |
|||
LET s = POS(where$,what$,s+LEN(what$)) |
|||
IF 0 = s THEN EXIT DO |
|||
LET c = c+1 |
|||
LOOP |
|||
LET countsubstring = c |
|||
END FUNCTION |
|||
PRINT "the three truths, th:", countSubstring("the three truths", "th") |
|||
PRINT "ababababab, abab:", countSubstring("ababababab", "abab") |
|||
END</lang> |
|||
==={{header|BASIC256}}=== |
==={{header|BASIC256}}=== |