Maple Professional
Maple Academic
Maple Student Edition
Maple Personal Edition
Maple Player
Maple Player for iPad
MapleSim Professional
MapleSim Academic
Maple T.A. - Testing & Assessment
Maple T.A. MAA Placement Test Suite
Möbius - Online Courseware
Machine Design / Industrial Automation
Aerospace
Vehicle Engineering
Robotics
Power Industries
System Simulation and Analysis
Model development for HIL
Plant Modeling for Control Design
Robotics/Motion Control/Mechatronics
Other Application Areas
Mathematics Education
Engineering Education
High Schools & Two-Year Colleges
Testing & Assessment
Students
Financial Modeling
Operations Research
High Performance Computing
Physics
Live Webinars
Recorded Webinars
Upcoming Events
MaplePrimes
Maplesoft Blog
Maplesoft Membership
Maple Ambassador Program
MapleCloud
Technical Whitepapers
E-Mail Newsletters
Maple Books
Math Matters
Application Center
MapleSim Model Gallery
User Case Studies
Exploring Engineering Fundamentals
Teaching Concepts with Maple
Maplesoft Welcome Center
Teacher Resource Center
Student Help Center
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
We can sort the results by frequency, as follows.
Use a filter to restrict attention to a limited class of characters.
See Also
character classes, sort, string, StringTools, StringTools[CountCharacterOccurrences], StringTools[Random], with
Download Help Document