41 lines
1.9 KiB
Plaintext
41 lines
1.9 KiB
Plaintext
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
|