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)

LetterCounts

LetterCounts["string"]
gives an association whose keys are the distinct letters in string, and whose values give the number of times those letters appear in string.

LetterCounts["string",n]
gives counts of the distinct n-grams consisting of runs of n letters in string.

LetterCounts["string",n,{"c1","c2",}]
allows the characters to appear in n-grams, in addition to ordinary letters.

Details and OptionsDetails and Options

  • LetterCounts[string,n] considers n-grams that start at every position in string and includes them in its counts if they contain only letters.
  • LetterCounts effectively uses LetterQ to determine whether to consider a character to be a letter.
  • LetterCounts has the option IgnoreCase. With the setting IgnoreCase->True, letters are in effect all converted to lower case before being counted.

ExamplesExamplesopen allclose all

Basic Examples  (4)Basic Examples  (4)

Count the letters in a string:

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

Non-letter characters are excluded from letter counts:

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

Count 2-grams of letters:

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

Specify a list of non-letter characters to be counted:

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