> For the complete documentation index, see [llms.txt](https://documentation.crossengage.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://documentation.crossengage.io/data-and-engagement-platform/messages/personalization/formatting-functions/string-formatting.md).

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


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://documentation.crossengage.io/data-and-engagement-platform/messages/personalization/formatting-functions/string-formatting.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
