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 ci to appear in n-grams, in addition to ordinary letters.
LetterCounts[{"string1","string2",…},…]
gives the counts for each of the stringi.
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 ci to appear in n-grams, in addition to ordinary letters.
LetterCounts[{"string1","string2",…},…]
gives the counts for each of the stringi.
Details 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.
- LetterCounts[BioSequence["type","seq"]] will give the letters of the string "seq".
Examples
open all close allBasic Examples (4)
Count the distinct letters in a string:
LetterCounts["banana"]Non-letter characters are excluded from letter counts:
LetterCounts["YT-1300"]Count the distinct 2-gram letter sequences in a string:
LetterCounts["ab12cd34ab12", 2]Count the distinct letters of each string in a list:
LetterCounts[{"hello", "world", "!"}]Scope (4)
Compute all 5-grams of letters in a string:
str = "aaaaaaaaaaaaa";LetterCounts[str, 5]The 5-grams start in positions 1 through 9 of the string:
LetterCounts[str]Specify a list of non-letter characters to be counted:
LetterCounts["TK-421", 1, {"1", "2"}]Count the distinct 2-gram letter sequences of each string in a list:
LetterCounts[{"banana", "tomato"}, 2]Find the letters of a biomolecular sequence:
LetterCounts[BioSequence["DNA", "ACCCAAGCTTAA"]]Options (2)
IgnoreCase (2)
The default setting IgnoreCase->False counts uppercase and lowercase characters independently:
LetterCounts["Alabama", IgnoreCase -> False]Use IgnoreCase->True to count all occurrences of a letter, regardless of case:
LetterCounts["Alabama", IgnoreCase -> True]Count n-grams regardless of case:
LetterCounts["abABabABabABabABabAB", 2, IgnoreCase -> True]LetterCounts["abABabABabABabABabAB", 2, IgnoreCase -> False]Applications (1)
Properties & Relations (1)
LetterCounts counts the distinct letter characters in a string:
LetterCounts["up-to-date documentation"]CharacterCounts additionally includes numbers, punctuation and whitespace:
CharacterCounts["up-to-date documentation"]Related Guides
Text
Wolfram Research (2015), LetterCounts, Wolfram Language function, https://reference.wolfram.com/language/ref/LetterCounts.html (updated 2024).
CMS
Wolfram Language. 2015. "LetterCounts." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2024. https://reference.wolfram.com/language/ref/LetterCounts.html.
APA
Wolfram Language. (2015). LetterCounts. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/LetterCounts.html
BibTeX
@misc{reference.wolfram_2026_lettercounts, author="Wolfram Research", title="{LetterCounts}", year="2024", howpublished="\url{https://reference.wolfram.com/language/ref/LetterCounts.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_lettercounts, organization={Wolfram Research}, title={LetterCounts}, year={2024}, url={https://reference.wolfram.com/language/ref/LetterCounts.html}, note=[Accessed: 13-June-2026]}