Jump to content

Count occurrences of a substring: Difference between revisions

Count occurrences of a substring in BASIC256 and Yabasic
(Count occurrences of a substring in BASIC256 and Yabasic)
Line 536:
 
See also: [[#Liberty BASIC|Liberty BASIC]], [[#PowerBASIC|PowerBASIC]], [[#PureBasic|PureBasic]].
 
==={{header|Applesoft BASIC}}===
<lang ApplesoftBasic>10 F$ = "TH"
Line 590 ⟶ 591:
160 LET I=I+LEN U$
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}}==
2,170

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.