Skip to tool

Apex Count occurrences Online

Count occurrences of a substring.

The output updates as you type. The tool processes input in your browser.

Worked example

The count uses non-overlapping matches. Check the case sensitivity setting before comparing results.

Needle
"one"
Case-insensitive
false
Sample input
one two one two one
Sample output
3

Using this operation in Apex

The interactive result uses JavaScript. Apex text utilities use the System namespace. Consider Salesforce transaction limits when applying an expensive transformation to many records.

Apex reference