padLeft
Description
Adds characters to the beginning 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, padLeft 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 padLeft to make all names 10 characters long:
Example query
Example output
{
    "name": "Chris",
    "name_padded": "XXXXXChris"
}
{
    "name": "David",
    "name_padded": "XXXXXDavid"
}
{
    "name": "John",
    "name_padded": "XXXXXXJohn"
}
Theme 
Light