!lm11
!rm76
Substring Search Function for Applesoft

Lee Reynolds' article in the January 1981 Call A.P.P.L.E. touched off this project.  When you are searching through text arrays for keywords, or through a mailing list for someone who lives on "XYZ Street", Applesoft can be vveeerrrrryyy slow.  This subroutine, linked in through the famous ampersand feature, will give you the speed your Apple is famous for.

Lee's program was quite similar to this one, but it did not allow the keyword or the string-to-be-searched to be expressions.  He left that extension as "an exercise for the reader".  Being one reader badly in need of exercise, I took up the challenge.

Although it is not really necessary, I used one of the newly discovered "secret" opcodes (which I wrote about last month) at line 2060.  If you like, you can replace that line with:
     2060 GS1    LDA (FACMO),Y
     2065        TAX



Here is a sample Applesoft program which uses the Substring Search Subroutine.  Line 10 loads the subroutine and calls 768 to link in the ampersand vector.  Line 120 reads in your search key.  If you just hit the RETURN key, the program quits.

Line 130 gets the next string to be searched from the DATA list.  If the value is ".", we are at the end of the list, so it loops back to line 110.

Line 140 calls our substring search subroutine to see if the key string can be found in the search string.  If not, it jumps back to line 130 to get another search string.  Lines 150-180 print the search string, emphasizing the portion that matched the key string by printing it in inverse.
