From Test-Scratch-Wiki
Using a Custom Block in combination with an algorithm, one can quickly check if a particular string passed in as an argument has a list of characters within it.
Programming
The following script can be used to check the condition. The variable (condition)
is evaluated to true of false depending on if the string has the particular characters. For this script, assume the following:
- "condition" is a variable used to determine true or false (the return variable)
- "i" is a variable used for iterating (moving form one character to another)
- "matches" is a variable used to determine the amount of characters detected in the base string
- "allLetters" is a list compiled of the characters being checked for; it is useful because lists have a built-in function for checking contained items
Note: | This is different than Checking if a String Contains a String because this script does not require the characters to be in sequential order. |
define check if (base) has (characters) set [condition v] to [false] delete (all v) of [allLetters v] set [i v] to (1) repeat (length of (characters)) //adds each letter to a list add (letter (i) of (characters)) to [allLetters v] change [i v] by (1) end set [i v] to (1) set [matches v] to (0) repeat (length of (base)) if <[allLetters v] contains (letter (i) of (base))> change [matches v] by (1) end change [i v] by (1) end if <(matches) = (length of [allLetters v])> set [condition v] to [true] end
See Also
— a similar script that requires the characters to be in order