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

# first

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

## first(text: String, amount: Number): String

Returns characters from the beginning of a string to the specified number of characters in the
string, for example, the first two characters of a string.

If the number is equal to or greater than the number of characters in the string, the function
returns the entire string.

_Introduced in DataWeave version 2.4.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 string to process.</p></td></tr><tr><td><p><code>amount</code></p></td><td><p>The number of characters to return. Negative numbers and <code>0</code> return an empty string. Decimals are rounded down to the nearest whole number.</p></td></tr></tbody></table>

### Example

This example returns the first five characters from a string.

#### Source

```DataWeave
%dw 2.0
import first from dw::core::Strings
output application/json
---
"hello world!" first 5
```

#### Output

```Json
"hello"
```

## first(text: Null, amount: Any): Null

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

_Introduced in DataWeave version 2.4.0._
