Contact Us 1-800-596-4880

countCharactersBy

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

Name Description

text

The string to which the predicate applies.

predicate

Expression to apply to each character in the text string. The expression must return a Boolean value.

Example

This example counts the digits in a string.

Source

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

Output

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.