Post Reply 
More spelunking: The undocumented find() command
12-02-2019, 07:38 AM
Post: #1
More spelunking: The undocumented find() command
Spelunking: The dangerous but thrilling hobby of exploring caves, such as the dark, mysterious, labyrinthine operating system of the HP Prime.

As you know, the well-documented instring() command finds the first occurrence of a substring in a string.

Example: instring("ABBA","B") returns 2, meaning that the 2nd character of "ABBA" is the first occurrence of "B" in it.

If you want to create a list of ALL the occurrences of a substring in a string, it would seem you need to write a little code to do so. But you don't need to, because there's an undocumented CAS function that does it for you.

In CAS view, find("ABBA","B") returns [2,3], which is all the positions of "B" in "ABBA". N.B. "find" must be typed in lowercase letters.

It's a CAS command, so if you want to use it in Home view or a non-CAS program, this syntax works:


Apparently find() also works on lists, e.g. find( {1,3,2,1,2,3,2,4}, 2) yields [3,5,7] which are the positions of 2 in the input list. Cool. Exploring other uses and syntaxes of find() is left as an exercise for the spelunker.

Disclaimer: As we recently learned in another thread, since this command is not mentioned in any documentation anywhere, it might not be in some old firmware versions, and it might disappear forever without warning in some future firmware update, and using it might "wipe all memory, fry your CPU, and potentially explode". But that's all part of the fun, because nobody should be spelunking who isn't fully aware that it's a dangerous sport. Big Grin

Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 

Messages In This Thread
More spelunking: The undocumented find() command - Joe Horn - 12-02-2019 07:38 AM

User(s) browsing this thread: 1 Guest(s)