LPOS, position of a substring in a list of strings by Joe Horn --> S/SX/G/GX PURPOSE: Search for a string within (not necessarily equal to) each string in a list of strings, and return the list index of the string in which it's found (NOT the position within that string!), or a zero if not found. Useful for data base searches and such; any programmer who works with lists of strings will find this handy. INSTRUCTIONS: List of strings, substring, LPOS --> position in list. EXAMPLES: { "THIS" "IS" "AN" "EXAMPLE" } "IS" LPOS --> 1 { "THIS" "IS" "AN" "EXAMPLE" } "AM" LPOS --> 4 { "THIS" "IS" "AN" "EXAMPLE" } "EL" LPOS --> 0 Two solutions follow, one in User RPL, one in System RPL. The System RPL routine is much faster than the User RPL one, especially for long lists. It works in all HP 48 versions. It is the one in binary form on this disk. Timing comparison for finding the last five characters of the 100th string in a list of 20-character strings: User-RPL solution: 6.242 seconds System-RPL solution: 0.419 seconds (15 times faster!) ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ ³ User-RPL solution ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ %%HP: T(3)A(D)F(.); \<< SWAP OVER + 1 DO GETI 4 PICK UNTIL POS END 1 - ROT ROT DROP2 \>> ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ ³ System-RPL solution ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ %%HP: T(3)A(D)F(.); ":: CK2&Dispatch # 53h :: ' :: # 1h POS$ #0<> ; POSCOMP UNCOERCE ; ;"