« Back to CVP - All Versions

Format string - custom element

Combination View Flat View Tree View
Threads [ Previous | Next ]
I needed to format a string into a certain length and then prepend some characters. Rather than write a custom element to do only that, I wrote the element in such a way as to allow it to be used for many formatting needs.
 
The details of the element are as follows:
 
Configuration:
 
Input String: the string to be formatted
Format String: The format to apply to the input string
Padding Side: Where to apply padding to the input string if nessecary; left, right, or none
truncating side: Where to apply truncating to the string if nessecary; left, right, or none
 
Behavior:
This element will take a format and a input string, and then make the input string look like the format string. 
The format string must have the section that is to be replaced by the input string surrounded by brackets [ ].
If the input is shorter than the area of the format string marked for replacement, and padding is set to "Left" or "Right", the input will be padded with the data in the format string.
If input is longer than the format area, the input will be truncated according to the setting.
Result will be stored in value
If there is an error, which would happen if the format string does not have the required brackets, value will contain the original input string.
 
Examples:
Input string: 12345
Format string: M#
Padding Side: Left
Truncating Side: Left
Result: Value == Mab12345#
 
Input string: 123456789
Format String:
Padding Side: Left
Truncating Side: Right
Result: Value == 1234
 

I currently don't have any requirements on the Format String input field.
 
If anyone knows how i could set the element to not validate in Call Studio unless it matched the pattern ".*\\[.+\\].*" (0 or more characters followed by [ then 1 or more characters, then ], then 0 or more characters), I'd like to know how I could do that. 

 
Feedback is welcomed!
Attachments: