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

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