# `pad`

## Description

**Alias for [`padLeft`](https://coralogix.com/docs/dataprime/language-reference/functions-reference/string/padleft/index.md).**

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, `pad` supports [two notations](https://coralogix.com/docs/dataprime/language-reference/functions-reference/index.md), **function** and **method** notation. These interchangeable forms allow flexibility in how you structure expressions.

```dataprime
pad(value: string, charCount: number, fillWith: string): string
```

```dataprime
(value: string).pad(charCount: number, fillWith: string): string
```

## 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:

```json
{ "name": "Chris" }
{ "name": "David" }
{ "name": "John" }
```

Use `pad` to make all names 10 characters long:

### Example query

```dataprime
create name_padded from pad(name, 10, 'X')
```

```dataprime
create name_padded from name.pad(10, 'X')
```

### Example output

```json
{
    "name": "Chris",
    "name_padded": "XXXXXChris"
}
{
    "name": "David",
    "name_padded": "XXXXXDavid"
}
{
    "name": "John",
    "name_padded": "XXXXXXJohn"
}
```
