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

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