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.

Reader Comments

There are no comments for this journal entry. To create a new comment, use the form below.

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>