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

# countCharactersBy

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

## countCharactersBy(text: String, predicate: (character: String) -> Boolean): Number

Counts the number of times an expression that iterates through each character in a string returns
`true`.

_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 which the <code>predicate</code> applies.</p></td></tr><tr><td><p><code>predicate</code></p></td><td><p>Expression to apply to each character in the <code>text</code> string. The expression must return a Boolean value.</p></td></tr></tbody></table>

### Example

This example counts the digits in a string.

#### Source

```DataWeave
%dw 2.0
import * from dw::core::Strings
output application/json
---
"42 = 11 * 2 + 20" countCharactersBy isNumeric($)
```

#### Output

```Json
7
```

## countCharactersBy(text: Null, predicate: (character: Nothing) -> Any): Null

Helper function to make `countCharactersBy` work with a `null` value.

_Introduced in DataWeave version 2.4.0._
