Workflow and ServiceDesk Community

 View Only

Pad Text 

Jun 13, 2012 09:46 AM

Component definition

This component adds a single character to the front or back of a string one or more times. For example, to format "1245" for an accounting report expecting 6 digits you could pad the front with 0s to get "001245".

Component icon

transform.png

Definition of component input value or values

Configuration
Input Value Name Input Value Data Type Req'd Example Format Explanation
Input Variable Name String Yes shortString This is the text that will padded.
Pad Length Int32 Yes 10 The final length the string should be. This must be greater than 0. NOTE: this is NOT the number of copies of the "Pad With Char" to add. If the input string is "1234" and "Pad Length" is 4, no characters will be added to the string.
Pad Type PadTypeEnum * Left Set to "Left" to add the "Pad With Char" to the front of the string. Set to "Right" to add the "Pad With Char" to the end of the string.
Pad With Char Char * 0 A single character to use to pad the input string out to "Pad Length".
Output Variable Name String Yes ItemList This is the name of the variable that will receive the newly padded string.

Definition of component output value or values

A variable with the name specified in "Output Variable Name" containing the padded string.

Connection information

None

Component settings

None

Use case

Space text out to form columns.

This component may be used to render a series of strings as a row in a table where each column is a known width. We will use spaces to pad the values in the row to fill the column. Depending how this component is used, it is possible to right justify, left justify or approximate centering a value in a column. For instance, suppose we need a table with 3 columns, each 10 characters wide. further, let's make the first column left justified, the second column centered and the 3rd column right justified. For the first column the parameters would be:

  • Input Variable Name: FirstValue
  • Pad Length: 10
  • Pad Type: Right
  • Pad With Char: " "
  • Output Variable Name: FirstColumn

We'll skip the second column for a moment because it has some complications and do the third column instead:

  • Input Variable Name: ThirdValue
  • Pad Length: 10
  • Pad Type: Left
  • Pad With Char: " "
  • Output Variable Name: ThirdColumn

Now for the second column. This one's a little more complicated because we have to pad both sides. First, we calculate how much to pad the left by subtracting the length of the value from the width of our column (suppose the second value is 3 characters long 10-3 = 7). We divide that number by 2 to determine how much to pad the left (7/2=3...drop any fractional part, we can't add partial spaces). So, to do the left side padding we need to pad it out to 6 characters (3 characters in the value + 3 characters of padding):

  • Input Variable Name: SecondValue
  • Pad Length: 6
  • Pad Type: Left
  • Pad With Char: " "
  • Output Variable Name: SecondColumn

Now, to finish centering the text we just pad the right side up to our final column width. One important note, the difference between the length of the value and the width of the column is an odd number and we don't have a way to do half a space so we have to have an extra space on one side or the other of our value. In this case we're putting the extra space to the right, it could as easily be placed in front of the string as well. In any caae, the parameters for this final padding are:

  • Input Variable Name: SecondColumn
  • Pad Length: 10
  • Pad Type: Right
  • Pad With Char: " "
  • Output Variable Name: SecondColumn

NOTE: We use SecondColumn as our input variable this time because it has our initial padding result in it. We could store that in a temporary variable instead, but as that value serves no other purpose it does not need to be kept.

[Example 2]

[Describe the use case. Insert screen shots or package files. Insert a description of how the settings are configured. Insert additional information about the use case that you are submitting.]

Statistics
0 Favorited
0 Views
0 Files
0 Shares
0 Downloads

Tags and Keywords

Related Entries and Links

No Related Resource entered.