Skip to content

padRight - Pad end of a string with a given character

padRight will add additional values to the end of a string up to a desired length.

Note

If the size of the string is greater than the desired character count, the string will be truncated from the end. For example, Chris with charCount of 3 becomes Chr.

Syntax

Like many functions in DataPrime, padRight supports two notations, function and method notation. These interchangeable forms allow flexibility in how you structure expressions.

padRight(value: string, charCount: number, fillWith: string): string
value: string.padRight(charCount: number, fillWith: string): string

Arguments

NameTypeRequiredDescription
valuestringtrueThe string to pad
charCountnumbertrueThe desired character count. If less than value, string will be truncated
fillWithstringtrueThe padding character

Note

fillWith MUST be a single character string.

Example - Ensuring all strings are the same length

Consider the following documents:

{
    "name": "Chris"
},
{
    "name": "David"
},
{
    "name": "John"
}

We may wish to make sure all of these strings are padded to the same length. We can do this using padRight:

create name_padded from padRight(name, 10, 'X')
create name_padded from name.padRight(10, 'X')

This will result in the following document:

{
    "name": "Chris",
    "name_padded": "ChrisXXXXX"
},
{
    "name": "David",
    "name_padded": "DavidXXXXX"
},
{
    "name": "John",
    "name_padded": "JohnXXXXXX"
}