Description

Linked Generators can be used to generate a substring of specified length from a given list of strings. 


What is a Substring?

A substring is derived from a common sequence of characters within a defined string. For example, a string such as "Tuesday" might have the following substrings: Tue, Tues, Tu, day, ues, sda, sday, or ue.


When should Substrings be used? 

Substrings should be used when you want to retrieve characters from a string. 


How can you create a Substring from a list of Strings?

Linked Generators can be used to create a random substring containing a specified number of characters from a list of strings. For this example, the following Generators will need to be linked as part of the Attribute's configuration: 

  • ListGen - Contains the list of strings. 
  • StringLengthGen - Evaluates the length of each string in the list. 
  • EvalCaseGen - Evaluate if the string is less than specified substring length.
  • PadGen - Pads the substring with blank when it is less than specified length. 
  • SubstringGen - Used to substring the padded strings
  • StringReplacementGenTrims the generated substring from the given string.


Note: For more information on Linked Generators, click here


Step 1: Specify List of Strings for Generating a Substring of Specified Length

The ListGen Generator will be used to enter a list of Strings that will be used to generate a substring.

  • Replace the currently assigned Generator with the ListGen Generator. Click the Replace Generator button when viewing the Attribute's configuration.



  • Click the Plus (+) for the ListGen Generator within the dialog window.



  • Enter each string value in the list Parameter and then click the Save Generator button for gen1.
  • Click on the list Parameter input field and type the string value. Then hit enter on your keyboard.


Step 2: Evaluate length of each string using StringLengthGen

The StringLengthGen Generator references the string specified in gen1 and generates the length of string.

  • Add the StringLengthGen Generator by clicking on the Add Generator button.


  •  Click the Plus (+) for the StringLengthGen Generator within the dialog window.



  • Double click on the reference Parameter to reference gen1 (ListGen).


Step 3: Evaluate if String is less than Specified Length using EvalCaseGen Generator

The EvalCaseGen Generator will be used to evaluate the string length for the specified length.

  • Add the EvalCaseGen Generator by clicking on the Add Generator button.


  •  Click the Plus (+) for the EvalCaseGen Generator within the dialog window.



  • Set the following Generator Parameter values: 
    • equation Parameter = var1>3
    • var1 Parameter = references gen2 (StringLengthGen)
    • caseTrue Parameter = references gen2 (StringLengthGen)
    • caseFalse Parameter = 3

       

Step 4: Pad String with Blank Space using the PadGen Generator 

The PadGen Generator is used to add padding when the string length is less than the specified length. If the string length is less, then a blank will be added to the right side of string to avoid error.

  • Add the PadGen Generator by clicking on the Add Generator button.


  • Click the Plus (+) for the PadGen Generator within the dialog window.



  • Set the following Generator Parameter values: 
    • attribute Parameter = references gen1 (ListGen)
    • padValue Parameter = #{BLANK}
    • padDirection Parameter = Right
    • padLength Parameter = references gen3 (EvalCaseGen)

 

Step 5: Use SubstringGen Generator to Substring the Padded Strings

The SubstringGen Generator references the padded string to substring for the specified length.

  • Add the SubstringGen Generator by clicking on the Add Generator button.


  • Click the Plus (+) for the SubstringGen Generator within the dialog window.



  • Set the following Generator Parameter values: 
    • referenceParameter = references gen4 (PadGen)
    • endIndexParameter = 3


Step 6: Trim the Generated Substring from the given String

Finally, the StringReplacementGen Generator is used to trim the generated substring from the given string. It trims the space from the string.

  • Add the StringReplacementGen Generator by clicking on the Add Generator button.


  • Click the Plus (+) for the StringReplacementGen Generator within the dialog window.



  • Set the following Generator Parameter values: 
    • value Parameter = references gen5 (SubstringGen)
    • fromText Parameter = [ \t]+$

       

Sample Output