PADSTRING

The function PADSTRING extends the length of a string by repeating another string either at the beginning or end of the original string.

This function "pads" a base string by appending a padding string repeated as many times as necessary to produce a string with the desired length. If the given string is longer than the length, the original string is returned unchanged. An optional fourth argument configures if the padding is added at the beginning ("LEFT"), or at the end ("RIGHT") of the base string.

Declaration

PADSTRING(base_string, pad_string, length, alignment) -> padded_string

Parameters

base_string (type: string)
The base string to pad.

pad_string (type: string)
The string to use for padding.

length (type: number)
The minimum length of the resulting string.

alignment (type: string)
The direction to pad the string, "RIGHT" is the default and will append the padding to base_string, while "LEFT" will prepend the padding to base_string.

Return Values

padded_string (type: string)
A string that is at least length long produced by repeating pad_string at either the beginning or end of base_string.

Examples

A common use case for the function PADSTRING is to ensure that each item in a list is the same length to aid browsing the list by eye.

PADSTRING("Buffalo Chicken Sandwich", ".", 60) ->  
"Buffalo Chicken Sandwich.................................."  
PADSTRING("Cheese Burger", ".", 60) ->  
"Cheese Burger............................................."

Notice that with a base_string that is longer than the minimum length it is returned with no changes.

PADSTRING("Roasted Carrots, English Pea Pesto, Feta, Almonds, Pea Shoots", ".", 60) ->  
"Roasted Carrots, English Pea Pesto, Feta, Almonds, Pea Shoots"  

By combining PADSTRING with the SUBSTRING and LENGTH functions, one can create a String that anonymizes sensitive information such as a credit card number, or social security number. When using PADSTRING in this way, be sure to do so in a Data Flow using a Secure Value Retrieval Data Operation. For the next example, assume that a variable named cc_number contains the credit card number 4111111111111111.

PADSTRING(SUBSTRING(cc_number, LENGTH(cc_number) - 4), "*", LENGTH(cc_number)) ->  
"************1111