---
schema_version: "1"
id: 838688984aaf31b4ee8a41a82da5a982f609d4a17961ae385bdaee6f0c07ec1d
title: trim
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/dataweave/2.3/dw-core-functions-trim.md
canonical_url: https://docs.mulesoft.com/dataweave/2.3/dw-core-functions-trim
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 3023c6fea7554bc906a2927e3831bfb711d132ade9f01c380456368ead19bc49
description: MuleSoft Documentation Site
release: "2.3"
latest: false
---
---
product: DataWeave
version: 2.3
---

# trim

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

## trim(String): String

Removes any blank spaces from the beginning and end of a string.

### Parameters

<table><colgroup><col> <col></colgroup><thead><tr><th>Name</th><th>Description</th></tr></thead><tbody><tr><td><p><code>text</code></p></td><td><p>The string from which to remove any blank spaces.</p></td></tr></tbody></table>

### Example

This example trims a string. Notice that it does not remove any spaces from the middle of the
string, only the beginning and end.

#### Source

```DataWeave
%dw 2.0
output application/json
---
{ "trim": trim("   my really long  text     ") }
```

#### Output

```JSON
{ "trim": "my really long  text" }
```

### Example

This example shows how `trim` handles a variety strings and how it handles a null value.

#### Source

```DataWeave
%dw 2.0
output application/json
---
{
  "null": trim(null),
  "empty": trim(""),
  "blank": trim("     "),
  "noBlankSpaces": trim("abc"),
  "withSpaces": trim("    abc    ")
}
```

#### Output

```JSON
{
  "null": null,
  "empty": "",
  "blank": "",
  "noBlankSpaces": "abc",
  "withSpaces": "abc"
}
```

## trim(Null): Null

Helper function that enables `trim` to work with a `null` value.
