RSS

Divide String Subflow

23 Oct
Divide String Subflow

Here’s a little flow for dividing a string into its parts depending on a separator string you specify.

For example, if you input the string “Back, to, the, Future” and specify a comma (,) separator you get a text collection variable with four items:

  1. Back
  2. to
  3. the
  4. Future

The Parts of the Flow

The constants and variables:

Constants and Variables

Constants and Variables

(The “Comma” constant is not necessary. I’ve included it because I’m using it as my default value for the “Separator” variable. By doing this the separator does not have to be provided for comma-separated strings.)

The Formulas:

Formulas

Formulas

The Flow:

Divide String Flow

Divide String Flow


Flow Logic

  1. First trim the input string and get the length of the separator string
    1. InputString = TRIMInputString
      1. TRIMInputString formula: TRIM(InputString)
    2. LENSeparator = GetLENSeparator
      1. GetLENSeparator formula: LEN(SeparatorString)
  2. (Start of Loop) Test the length of the input string. If length equals zero, exit.
    1. LENInputString formula: LEN(InputString)
  3. Test for the presence of the separator at the beginning and the end of the string. If present, remove.
    1. SeparatorAtEnd formula: IF(RIGHT(InputString, LENSeparator) = Separator, True, False)
    2. SeparatorAtStart formula: IF(LEFT(Inputstring, LENSeparator) = Separator, True, False)
    3. To remove separator from front of string use the RIGHTInputString formula:
      1. RIGHT(InputString, LEN(InputString) – NextSeparatorLocation – LENSeparator +1)
    4. To remove separator from end of string use the RemoveFromEnd formula:
      1. LEFT(InputString, LEN(InputStringLENSeparator)
  4. Test for the location of the next separator string
    1. NextSeparatorLocation formula: FIND(Separator, InputString)
    2. If the location is zero, then there aren’t any more divisions so save the last item and exit
  5. Add string to a collection variable
    1. StringCollection Add LEFTInputString
      1. LEFTInputString formula: LEFT(InputString, FIND(SeparatorString, InputString) -1)
  6. Put the remaining string into a temporary variable
    1. TempStr = RIGHTInputString
  7. Assign the temporary variable to the input string variable
    1. InputString = TempStr
  8. Start over at #2

There you have it!

Advertisements
 
Leave a comment

Posted by on October 23, 2015 in Tools, Visual Flow

 

Tags: ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: