Workflow Example: Text [Remove 'N' Lines]

This workflow takes a block of text and offers to remove a number of lines for the user. The user can select whether to remove them from the beginning or the end of the text and the workflow uses some validation for numeric data entry to put in some better edge case handling.

The workflow starts by storing the text and counting the number of lines in it (ten in this case). It then asks the user how many lines they would like to remove. The input must be a number, but beyond that it is validated by several actions to be a positive integer less than or equal to the maximum number of lines in the text. The input begins by being rounded down to the nearest integer. This is then compared against 0 and the number of lines to ensure it falls between them (inclusively). If it does not then the user receives a notification and is prompted to enter the number again (via a loop that will give the user 42 chances to enter the right number … after which anyone might give up the will to live ;-) )

Once the number has been verified the user is presented with the option to remove the lines from the start or the end of the text.

When removing the lines, the workflow splits the text by new lines and loops through the lines. It uses the index number of the loop to determine whether to retain the line or not. If it should then this is added to an Output variable.

Once the lines have all been processed, the content of the Output variable is recombined (with new lines as the separator) and the lines are displayed to the end user via a Quick look action. Finally an Exit Workflow action is triggered to break out of the loop used to validate the input.

  • [Download Link](/assets/workflow-examples/Example - Text %5BRemove ‘N’ Lines%5D (196f5d2a12e54c34b39296c366a53b1b).wflow).

![](/assets/workflow-examples/Example - Text %5BRemove ‘N’ Lines%5D.jpeg)

Tags: | workflow |