StringTools[CharacterFrequencies] - compute the number of occurrences of each character in a string
|
Calling Sequence
|
|
CharacterFrequencies( s, filter )
|
|
Parameters
|
|
s
|
-
|
Maple string
|
filter
|
-
|
(optional) name or string; character class filter specifying frequencies returned
|
|
|
|
|
Description
|
|
•
|
The CharacterFrequencies(s) command returns an expression sequence of equations of the form character = frequency, where character is a single character string, and frequency is the number of times the corresponding character occurs in the string s.
|
•
|
The expression CharacterFrequencies( s ) is equivalent to seq( ch = CountCharacterOccurrences( s, ch ), ch = Support( s ) ), but computes the latter result more efficiently.
|
•
|
The frequencies appear in ASCII order; that is, in order of the numeric byte value of the character on the left-hand side of each equation. For an example illustrating how to sort by frequency, see the examples below.
|
•
|
To specify that the frequencies of only certain characters be returned, use an optional character class filter parameter. The parameter can be a string of characters to return, for example, "abcd" or one of the following character class names.
|
alpha
|
alphabetic characters
|
alnum
|
alphabetic characters and digits
|
ascii
|
ASCII (7-bit) characters
|
binary
|
"0" and "1"
|
cntrl
|
control characters
|
digit
|
decimal digits
|
hdigit
|
hexadecimal digits (both cases)
|
ident
|
identifier characters
|
ident1
|
leading identifier characters
|
lower
|
lower cases letters
|
odigit
|
octal digits (0-7)
|
space
|
whitespace characters
|
upper
|
upper case letters
|
vowel
|
vowels (both cases)
|
|
|
|
|
|
|
Examples
|
|
>
|
|
>
|
|
>
|
|
| (1) |
>
|
|
| (2) |
>
|
|
| (3) |
>
|
|
| (4) |
>
|
|
| (5) |
>
|
|
| (6) |
>
|
|
>
|
|
| (7) |
We can sort the results by frequency, as follows.
>
|
|
| (8) |
Use a filter to restrict attention to a limited class of characters.
>
|
|
| (9) |
>
|
|
| (10) |
>
|
|
| (11) |
|
|
Download Help Document
Was this information helpful?