# String Formatting

CrossEngage offers two string formatting functions:

1. `trim` - used to remove whitespace around a string
2. `substring` - used to display a substring of an existing string

### trim Function

The `trim` helper function removes white spaces from the start and end of a string. The syntax of this formatting function is:

```jsx
{{#trim}}{{[attribute]}}{{/trim}}
```

| Property    | Description                                                                                                                 |
| ----------- | --------------------------------------------------------------------------------------------------------------------------- |
| `attribute` | Any user or event attribute or any information extracted through any of the helper functions. e.g. `{{user.[traits.email}}` |

#### Removing the white space around an email attribute

For the example below, we use  `john.doe@crossengage.io` as the value of the user's email attribute.

```jsx
{{#trim}}{{user.[traits.email]}}{{/trim}}
```

Once the function is evaluated, it displays `john.doe@crossengage.io` in the section where it is used in the message. &#x20;

#### Removing the white space around a product name field

Using the helper function `#findProduct`, we search for a particular `sku` and format the result's  `[properties.name]` attribute. For the example below, we use `iPhone 8 Plus` as the value of the product's name.

```jsx
{{#trim}}{{[properties.name]}}{{/trim}}
```

Once the function is evaluated, it displays `iPhone 8 Plus` in the section where it is used in the message. &#x20;

### substring Function

To extract a substring from a text field, we can use the `substring` function. This can be quite useful in breaking down text fields such as address, IBAN, or Business Unit, where different parts of the string might have Independent meaning.eaning.

```jsx
{{substring '{
    "propertyName": [Attribute], 
    "start": [Substring start],
    "length": [Substring length]
    }'
}}
```

<table data-header-hidden><thead><tr><th width="353">Property</th><th>Description</th></tr></thead><tbody><tr><td>Property</td><td>Description</td></tr><tr><td><code>propertyName</code></td><td><strong>Required</strong>. Any user or event attribute or any information extracted through any of the helper functions.</td></tr><tr><td><code>start</code></td><td><strong>Required</strong>. The index of the character in the original string where the substring starts. e.g. <code>1</code> refers to the first character in the string, <code>3</code> to the third character.</td></tr><tr><td><code>length</code></td><td><strong>Required</strong>. The number of characters the substring extracts from the original string. e.g. <code>10</code></td></tr></tbody></table>
