CharacterCounts

CharacterCounts["string"]

gives an association whose keys are the distinct characters in string, and whose values give the number of times those characters appear in string.

CharacterCounts["string",n]

gives counts of the distinct n-grams consisting of runs of n characters in string.

Details and Options

Examples

open allclose all

Basic Examples  (3)

Count the distinct characters in a string:

Character counts include all characters, including numbers, punctuation, and whitespace:

Count the distinct 2-gram sequences in a string:

Options  (1)

IgnoreCase  (1)

Count n-grams regardless of case:

Neat Examples  (1)

Find the most frequently occurring characters in the Gettysburg Address:

Do the same for 3-character sequences:

Introduced in 2015
 (10.1)