---
schema_version: "1"
id: 760c45ab85c2108689c753aefb7cd35a1a32ba953e8a93d2cd96256c0e4bc55d
title: withMaxSize
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/dataweave/2.6/dw-strings-functions-withmaxsize.md
canonical_url: https://docs.mulesoft.com/dataweave/2.6/dw-strings-functions-withmaxsize
source_site: docs.mulesoft.com
content_type: documentation
content_hash: aa9b0cde8ff860cf5893756a09303bb47bff5f22cf7fc69a8ce28380cf244010
description: MuleSoft Documentation Site
release: "2.6"
latest: false
---
---
product: DataWeave
version: 2.6
---

# withMaxSize

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

## withMaxSize(text: String, maxLength: Number): String

Checks that the string length isn’t greater than the specified `maxLength`. If the string is longer,
the function returns a substring that starts at the beginning of the string and is `maxLength`
characters long.

_Introduced in DataWeave version 2.3.0._

### 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 input string.</p></td></tr><tr><td><p><code>maxLength</code></p></td><td><p>The maximum length of the string.</p></td></tr></tbody></table>

### Example

This example shows how `withMaxSize` behaves with different `maxLength` values for the same string.
Note that if `withMaxSize` is 0, the function returns an unmodified string. If the input is `null`,
the output is always `null`.

#### Source

```DataWeave
%dw 2.0
import withMaxSize from dw::core::Strings
output application/json
---
{
   a: "123" withMaxSize 10,
   b: "123" withMaxSize 3,
   c: "123" withMaxSize 2,
   d: "123" withMaxSize 0,
   e: null withMaxSize 23,
}
```

#### Output

```JSON
{
  "a": "123",
  "b": "123",
  "c": "12",
  "d": "123",
  "e": null
}
```

## withMaxSize(text: Null, maxLength: Number): Null

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

_Introduced in DataWeave version 2.3.0._
