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 allclose allBasic Examples (4)
Scope (4)
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:
Applications (1)
Properties & Relations (1)
LetterCounts counts the distinct letter characters in a string:
CharacterCounts additionally includes numbers, punctuation and whitespace:
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