padRight
Description
Adds characters to the end of a string until it reaches the desired length. If the string is longer than the target length, it is truncated from the end.
Note
The fillWith
argument must be a single-character string.
Syntax
Like many functions in DataPrime, padRight
supports two notations, function and method notation. These interchangeable forms allow flexibility in how you structure expressions.
Arguments
Name | Type | Required | Description |
---|---|---|---|
value | string | true | The string to pad |
charCount | number | true | Desired total length of the string; if smaller than current length, the string is truncated |
fillWith | string | true | The single character used for padding |
Example
Ensure all strings are the same length
Consider the following documents:
Use padRight
to make all names 10 characters long:
Output
{
"name": "Chris",
"name_padded": "ChrisXXXXX"
}
{
"name": "David",
"name_padded": "DavidXXXXX"
}
{
"name": "John",
"name_padded": "JohnXXXXXX"
}
Theme
Light