06-12-2020 07:21 AM
My user will be uploading a list of commands which are then read off sequentially and sent as messages to different loops in the system.
Every line of this array must be in the exact format the loops are expecting, or the loop will receive an unknown string and error.
I want to be able to check through this list for anything that doesn't match one of the 5 expected commands. Like a 'does this string exactly match any of these strings?' yes/no
So far all I can think is using 5 different while loops containing the search array function. Each of these will increment through the array searching for a different command, if all 5 of the while loops give a -1 then the array line hasn't matched any of the commands so will trigger an error to the user (as one of the commands must be mistyped).
But that sounds absurd?
Solved! Go to Solution.
06-12-2020 07:31 AM - edited 06-12-2020 07:36 AM
Create a string array constant of executable commands to compare with the array of commands that have been read from your user. Use a for loop to index the user commands and check each one using "Search 1D Array" against the array of possible commands. If the result (index) is >=0 then you have a match. AND "And Array Elements" all of them to see if they all are good.
06-12-2020 07:40 AM
Depending on the format of the commands, it can be either a simple list you check against with a Search 1D Array, or if more dynamic a list of 5 regexps. If it's even more advanced you're into language interpretation and need recursive functionality, like with a typical text programming language with loops within cases within structures ...
06-12-2020 11:00 AM
You can compare each with an array of valid commands or with a set of valid commands.
Here are two examples to clean the array of commands:
You could even do the "sending" right inside these loops and only send the valid command using a case structure.