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.

CharacterCounts[{"string1","string2",},]

gives the counts for each of the stringi.

Details and Options

Examples

open allclose all

Basic Examples  (3)

Count the distinct characters in a string:

Count the distinct 2-gram sequences in a string:

Count the distinct characters of each string in a list:

Scope  (3)

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

Count the distinct 2-gram sequences of each string in a list:

Find the characters of a biomolecular sequence:

Options  (2)

IgnoreCase  (2)

The default setting IgnoreCase->False counts uppercase and lowercase characters independently:

Use IgnoreCase->True to count all occurrences of a letter, regardless of case:

Count n-grams regardless of case:

Applications  (1)

Count the characters in the full English names of each of the first 10 positive integers:

Merge the counts:

Properties & Relations  (1)

CharacterCounts counts the distinct characters in a string, including numbers, punctuation and whitespace:

LetterCounts includes only the letter characters:

Neat Examples  (2)

Find the 20 most frequently occurring characters in a body of text:

Do the same for 3-character sequences:

Make whitespace counts easier to see:

Wolfram Research (2015), CharacterCounts, Wolfram Language function, https://reference.wolfram.com/language/ref/CharacterCounts.html (updated 2024).

Text

Wolfram Research (2015), CharacterCounts, Wolfram Language function, https://reference.wolfram.com/language/ref/CharacterCounts.html (updated 2024).

CMS

Wolfram Language. 2015. "CharacterCounts." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2024. https://reference.wolfram.com/language/ref/CharacterCounts.html.

APA

Wolfram Language. (2015). CharacterCounts. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/CharacterCounts.html

BibTeX

@misc{reference.wolfram_2024_charactercounts, author="Wolfram Research", title="{CharacterCounts}", year="2024", howpublished="\url{https://reference.wolfram.com/language/ref/CharacterCounts.html}", note=[Accessed: 05-December-2024 ]}

BibLaTeX

@online{reference.wolfram_2024_charactercounts, organization={Wolfram Research}, title={CharacterCounts}, year={2024}, url={https://reference.wolfram.com/language/ref/CharacterCounts.html}, note=[Accessed: 05-December-2024 ]}