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

# substringBefore

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

## substringBefore(text: String, separator: String): String

Gets the substring before the first occurrence of a separator. The separator is not returned.

_Introduced in DataWeave version 2.2.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>separator</code></p></td><td><p>String to search for.</p></td></tr></tbody></table>

### Example

This example shows how `substringBefore` behaves with different inputs and sizes.

#### Source

```DataWeave
%dw 2.0
import * from dw::core::Strings
output application/json
---
{
  "a": substringBefore(null, "'"),
  "b": substringBefore("", "-"),
  "c": substringBefore("abc", "b"),
  "d": substringBefore("abc", "c"),
  "e": substringBefore("abc", "d"),
  "f": substringBefore("abc", "")
}
```

#### Output

```JSON
{
  "a": null,
  "b": "",
  "c": "a",
  "d": "ab",
  "e": "",
  "f": ""
}
```

## substringBefore(text: Null, separator: String): Null

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

_Introduced in DataWeave version 2.2.0._
