CountCharacters - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

FileTools[Text]

 CountCharacters
 count the occurrences of a character in a file or count the total number of characters in a file

 Calling Sequence CountCharacters(file) CountCharacters(file, character)

Parameters

 file - file descriptor or filename character - string of length 1; character to count

Description

 • The CountCharacters(file) command counts the number of characters from file's current position to the end of the file.
 • The CountCharacters(file, character) command counts the number of occurrences of character from file's current position to the end of the file.
 • As CountCharacters is a Text function, it counts characters, not bytes.  Therefore characters represented as multiple bytes, (like "\\r\\n") are counted as a single character.  This means the number of characters in a file can differ from the number of bytes in a file.
 • An error is raised if file is not a valid descriptor or if the filename does not exist.

Examples

 > $\mathrm{with}\left(\mathrm{FileTools}\right):$
 > $\mathrm{with}\left(\mathrm{Text}\right):$
 > $\mathrm{WriteString}\left("foo","121312141213121"\right):$
 > $\mathrm{Close}\left("foo"\right):$
 > $\mathrm{CountCharacters}\left("foo"\right)$
 ${15}$ (1)
 > $\mathrm{CountCharacters}\left("foo","1"\right)$
 ${8}$ (2)
 > $\mathrm{CountCharacters}\left("foo","2"\right)$
 ${4}$ (3)
 > $\mathrm{Position}\left("foo",8\right):$
 > $\mathrm{CountCharacters}\left("foo"\right)$
 ${7}$ (4)
 > $\mathrm{CountCharacters}\left("foo","1"\right)$
 ${4}$ (5)
 > $\mathrm{CountCharacters}\left("foo","2"\right)$
 ${2}$ (6)
 > $\mathrm{Remove}\left("foo"\right):$