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

# 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._
