Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
40
Task/Search-a-list/PowerBASIC/search-a-list.basic
Normal file
40
Task/Search-a-list/PowerBASIC/search-a-list.basic
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
FUNCTION PBMAIN () AS LONG
|
||||
DIM haystack(54) AS STRING
|
||||
ARRAY ASSIGN haystack() = "foo", "bar", "baz", "quux", "quuux", "quuuux", _
|
||||
"bazola", "ztesch", "foo", "bar", "thud", "grunt", "foo", _
|
||||
"bar", "bletch", "foo", "bar", "fum", "fred", "jim", _
|
||||
"sheila", "barney", "flarp", "zxc", "spqr", ";wombat", "shme", _
|
||||
"foo", "bar", "baz", "bongo", "spam", "eggs", "snork", "foo", _
|
||||
"bar", "zot", "blarg", "wibble", "toto", "titi", "tata", _
|
||||
"tutu", "pippo", "pluto", "paperino", "aap", "noot", "mies", _
|
||||
"oogle", "foogle", "boogle", "zork", "gork", "bork"
|
||||
DIM needle AS STRING, found AS LONG, lastFound AS LONG
|
||||
DO
|
||||
needle = INPUTBOX$("Word to search for? (Leave blank to exit)")
|
||||
IF needle <> "" THEN
|
||||
' collate ucase -> case insensitive
|
||||
ARRAY SCAN haystack(), COLLATE UCASE, = needle, TO found
|
||||
IF found > 0 THEN
|
||||
lastFound = found
|
||||
MSGBOX "Found """ & needle & """ at index " & TRIM$(STR$(found - 1))
|
||||
IF found < UBOUND(haystack) THEN
|
||||
DO
|
||||
ARRAY SCAN haystack(lastFound), COLLATE UCASE, = needle, TO found
|
||||
IF found > 0 THEN
|
||||
MSGBOX "Another occurence of """ & needle & """ at index " & _
|
||||
TRIM$(STR$(found + lastFound - 1))
|
||||
lastFound = found + lastFound
|
||||
ELSE
|
||||
MSGBOX "No more occurences of """ & needle & """ found"
|
||||
EXIT DO 'will exit inner DO, not outer
|
||||
END IF
|
||||
LOOP
|
||||
END IF
|
||||
ELSE
|
||||
MSGBOX "No occurences of """ & needle & """ found"
|
||||
END IF
|
||||
ELSE
|
||||
EXIT DO
|
||||
END IF
|
||||
LOOP
|
||||
END FUNCTION
|
||||
Loading…
Add table
Add a link
Reference in a new issue