Wolfram Language & System 10.4 (2016)|Legacy Documentation

This is documentation for an earlier version of the Wolfram Language.View current documentation (Version 11.2)

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 OptionsDetails and Options

ExamplesExamplesopen allclose all

Basic Examples  (3)Basic Examples  (3)

Count the distinct characters in a string:

In[1]:=
Click for copyable input
Out[1]=
In[2]:=
Click for copyable input
Out[2]=

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

In[1]:=
Click for copyable input
Out[1]=
In[2]:=
Click for copyable input
Out[2]=
In[3]:=
Click for copyable input
Out[3]=

Count the distinct 2-gram sequences in a string:

In[1]:=
Click for copyable input
Out[1]=
In[2]:=
Click for copyable input
Out[2]=
Introduced in 2015
(10.1)