Count occurrences of a substring: Difference between revisions

Content added Content deleted
(Count occurrences of a substring in BASIC256 and Yabasic)
Line 536: Line 536:


See also: [[#Liberty BASIC|Liberty BASIC]], [[#PowerBASIC|PowerBASIC]], [[#PureBasic|PureBasic]].
See also: [[#Liberty BASIC|Liberty BASIC]], [[#PowerBASIC|PowerBASIC]], [[#PureBasic|PureBasic]].

==={{header|Applesoft BASIC}}===
==={{header|Applesoft BASIC}}===
<lang ApplesoftBasic>10 F$ = "TH"
<lang ApplesoftBasic>10 F$ = "TH"
Line 590: Line 591:
160 LET I=I+LEN U$
160 LET I=I+LEN U$
170 GOTO 130</lang>
170 GOTO 130</lang>

==={{header|BASIC256}}===
{{trans|Run BASIC}}
<lang freebasic>print countSubstring("the three truths","th")
print countSubstring("ababababab","abab")
end

function countSubstring(s$,find$)
i = 1
while instr(s$,find$,i) <> 0
countSubstring += 1
i = instr(s$,find$,i) + length(find$)
end while
end function</lang>
{{out}}
<pre>Igual que la entrada de Run BASIC.</pre>

==={{header|Yabasic}}===
{{trans|Run BASIC}}
<lang yabasic>print countSubstring("the three truths","th")
print countSubstring("ababababab","abab")
end

sub countSubstring(s$,find$)
countSubstring = 0
i = 1
while instr(s$,find$,i) <> 0
countSubstring = countSubstring + 1
i = instr(s$,find$,i) + len(find$)
end while
return countSubstring
end sub</lang>
{{out}}
<pre>Igual que la entrada de Run BASIC.</pre>



=={{header|Batch File}}==
=={{header|Batch File}}==