Best way to find if text contains a set element?

I did search for “Set” and didn’t see a hit that fit. I’m guessing RegEx might come into play. What is the best way to see if some text contains all, or any, of the letters in a set (array) of letters (single or multiple as in a, b,c or ab, cd, ef, etc.) Manually, to a limited depth, I can imagine doing it with the Select statement set to and/or as appropriate - then continuing with SelectWithin (or SelectAdditional). As the set, if not case sensitive and only alphabetic, would only have at most 25 letters, maybe an humungus IF … and … and …, or an IF … or … or … or … would be the way to do it. But with all the new toys in PanX, I’m wondering if there is a super efficient way to do this.

Somehow, in the back of my mind, this topic has been addressed. But it might have been in a Xojo, SimplyFortran, or Python forum. xDev online magazine did cover sets in an article a few issues back. But maybe it was discussed here. Don’t get old - unless you have a sense of humor about memory :slight_smile:

The structure that pops into mind is something like an “IsIn” relationship. With just one set element, “contains” is elementary. But with multiple elements the IF construction quickly grows large.

I can’t really say what’s “best” because I don’t really understand your application. But it could be done with the contains and or operators.

 text contains "a" or text contains "b" or ... or text contains "ef"

It could definitely be done with a regular expression.

I think it could be done with arrayfilter( also.

let set = "a,b,c,ab,cd,ef"
let containsSet = arrayfilter(text,",",{?(text contains import(),"x","")}) contains "x"

The result of the arrayfilter( will contain one or more x’s if any of the items in the set are contained in the text. So at the end we just need to check if the result contains at least one “x”. (The choice of “x” was arbitrary.)

Thank you Jim. I used something like that. As you can see that contains, contains, contains, can get pretty long.

This exercise was to solve a remaining “word” in a cipher type called a Tridigital. A short explanation is each message word is shown as a series of numbers (0 -9), one number per letter in the word, but each number can represent up to 3 letters. that gives 10 possible numbers but one number is used to identify a word space (you don’t know which one) and with the remaining 9 (3 x 9 = 27), one of them represents only 2 letters instead of three (you don’t know which one).

So I had the “word”, 34226870. As this was the only remaining word to decode in the message, I had already identified all but about 12 letters.

Long ago, in the world of 3.5 floppies, I bought a 300,000-word dictionary, and using Panorama, I broke it into word length groups with a secondary breakdown into word with no repeating letters and those with (pattern words). In this case, I opened both word-length eight files (.txt files) appending them together.

With around 12 - 15 letters to worked with, first I used the six-choice Select window and a select BeginsWith "or"ing the six choices (okay, it was Pan6 :blush:), then did it again for the remaining candidate letters with SelectAdditional. Then I removed UnSelected.
From that, I repeated the process using EndsWith - again OR-ing the candidate letters and using SelectAdditional, removing the rest with Remove Unselected. That got my word list down to about 280.

From there, I switched to Formula Find/Select, with the structure A[2,2] = “C” or A[2,2] = “F”, or A[2,2] = “J” … listing the 12 to 15 candidate letters for each position. After each selection I Removed Unselected. It took only one more position (A[3,3] = …) selection to reduce the list to a number I could just review. Once the number of possible words was down to about 100, given the context of the message, it was easy to pick out the appropriate one without having to do further reductions.

The word was “cheering” and I had an idea that might be it from earlier pencil and paper work on the cipher. But when I looked cheering up on my iPhone dictionary, it didn’t have it. (it only had cheerily). So that’s why I went the extra mile to make sure some other word wouldn’t fit better. The context was unusual, “…it’s cheering to know …” rather than a more usual, “The crowd was cheering …” So looking at all the words that could fit was warranted.

I can see now that it’s not so much that the word itself contains a set of letters as it is that certain positions in the word contain one of the letters in the set.

So if I decide to make a selecting function, I’ll need to pass it a word list, and a set of candidate letters for each position in the word.

Panorama is so much fun. I don’t know why everyone isn’t using it.