Is there an attribute or action code for character count?
You could also try using attribute $EstimatedNoteSize as a proxy for character count. Below an example in a test file. Adding an initial “H” to the text field leads to a jump in value from 6 to 431 for the $EstimatedNoteSize attribute. Every subsequent additional character adds 2 to the total e.g. 433, 435…
The action code
($EstimatedNoteSize-429)/2 should then in theory give you the character count for the text field. As I don’t know the algorithm behind the $EstimatedNoteSize attribute I’m not sure how robust this approach is and it would require some experimentation.
As is noted for $EstimatedNoteSize:
This provides a rough estimate of the space that the note will require on disk.
Given that there methods (posts) above that return accurate character counts, back-calculation from $EstimatedNoteSize is always likely to be less accurate for character counts.
This demo TBX, text-size.tbx (116.6 KB), shows that
$Text.size are equal and that both are the character count of the plain text of the note $Text. RTF styling (font type, italic, highlighting) has no effect on the count. But ‘invisible’ characters like space, link break, tab, and such do contribute to the count.
Screen grab from the TBX:
$EstimatedNoteSizetakes into account the approximate size of the note text, including images embedded in the text. Its intended use is to identify notes with unexpectedly-large images.
$Text.size()now report the length of the UTF-16 representation of the text of the notes. As you likely know, Unicode can represent more than a million distinct characters! The characters that count as “1 character” here are those in the base multilingual plane which include most modern languages and many common symbols. Other characters — notably emoji — count as “2 characters” for $TextLength and $Text.size.
Ah, yes. My bad. I will update notes accordingly.
Done. See: new aTbRef article ‘Counting characters in strings’.