FileTools[Text]
CountCharacters
count the occurrences of a character in a file or count the total number of characters in a file
Calling Sequence
Parameters
Description
Examples
CountCharacters(file)
CountCharacters(file, character)
file
-
file descriptor or filename
character
string of length 1; character to count
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.
with⁡FileTools:
with⁡Text:
WriteString⁡foo,121312141213121:
Close⁡foo:
CountCharacters⁡foo
15
CountCharacters⁡foo,1
8
CountCharacters⁡foo,2
4
Position⁡foo,8:
7
2
Remove⁡foo:
See Also
FileTools[Position]
FileTools[Remove]
FileTools[Text][Close]
FileTools[Text][CountLines]
FileTools[Text][WriteString]
IO_errors
Download Help Document