Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
32
Task/String-matching/BBC-BASIC/string-matching.basic
Normal file
32
Task/String-matching/BBC-BASIC/string-matching.basic
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
first$ = "The fox jumps over the dog"
|
||||
|
||||
FOR test% = 1 TO 3
|
||||
READ second$
|
||||
starts% = FN_first_starts_with_second(first$, second$)
|
||||
IF starts% PRINT """" first$ """ starts with """ second$ """"
|
||||
ends% = FN_first_ends_with_second(first$, second$)
|
||||
IF ends% PRINT """" first$ """ ends with """ second$ """"
|
||||
where% = FN_first_contains_second_where(first$, second$)
|
||||
IF where% PRINT """" first$ """ contains """ second$ """ at position " ; where%
|
||||
howmany% = FN_first_contains_second_howmany(first$, second$)
|
||||
IF howmany% PRINT """" first$ """ contains """ second$ """ " ; howmany% " time(s)"
|
||||
NEXT
|
||||
DATA "The", "he", "dog"
|
||||
END
|
||||
|
||||
DEF FN_first_starts_with_second(A$, B$)
|
||||
= B$ = LEFT$(A$, LEN(B$))
|
||||
|
||||
DEF FN_first_ends_with_second(A$, B$)
|
||||
= B$ = RIGHT$(A$, LEN(B$))
|
||||
|
||||
DEF FN_first_contains_second_where(A$, B$)
|
||||
= INSTR(A$, B$)
|
||||
|
||||
DEF FN_first_contains_second_howmany(A$, B$)
|
||||
LOCAL I%, N% : I% = 0
|
||||
REPEAT
|
||||
I% = INSTR(A$, B$, I%+1)
|
||||
IF I% THEN N% += 1
|
||||
UNTIL I% = 0
|
||||
= N%
|
||||
Loading…
Add table
Add a link
Reference in a new issue