How to get word/character count with Text Blaze

Any self-respecting text editing app has a word/character count feature nowadays. But sometimes, you'll be using Text Blaze to fill out a form, and you'll come across a text field that has a word/character limit, so you want to avoid exceeding that while you're Inserting your snippet.

Here are three snippet bits that you can use for that.

Just copy whichever one you want to use, paste it inside your snippet, and change the variable names to match the name of the formtext or formparagraph you want to use it on.

Here are the snippets.

Word count:

{formparagraph: name=data; default=the quick brown fox jumped over the lazy dogs}
{=count(split(data, " "))}

Character count including spaces:

{formparagraph: name=data; default=the quick brown fox jumped over the lazy dogs}
{=len(data) }

Character count excluding spaces:

{formparagraph: name=data; default=the quick brown fox jumped over the lazy dogs}

{=count(extractregexall(data, "[^\s]")) }

Hope this helps :slight_smile:

EDIT: In my enthusiasm, I hadn't realized that the second and third snippets could be A LOT simpler.

Big thanks to @scott for pointing out the error of my ways :blush:

I've now updated the snippets accordingly. Enjoy!

As an added note, the third snippet is using extractregexall() to extract all characters that are not white space (represented by [^\s])

1 Like

Here's a snippet I recently wrote to help our teams with SMS messages where character limits are a big deal. Check out what happens when the user reaches and surpasses the limit!

{note: preview=no; insert=no; trim=yes}
Variables:
{sublen={=len(message)}}

{endnote: trim=yes}

{formparagraph: name=message; cols=40; rows=4; trim=left}{note}
Character Counter: {=sublen} {if: {=185-{=sublen}<15}}Characters Remaining: {=185-{=sublen}}{else}Characters Remaining: {=185-{=sublen}}{endif}
{if: (186-{=sublen})<=0}{error: MAX CHARACTERS REACHED!; block=yes; show=default}{endif}
{if: (186-{=sublen})<=0}{error: CANNOT SEND MESSAGE UNTIL SHORTENED.; block=yes; show=default}{endif}
{endnote: trim=yes}

4 Likes

Thanks! I was looking for something just like that (the first snippet for a word count). I just tried it with several long texts — just be aware there will be a small error rate, e. g. for a 1810 word text I got 1801 words after reformatting, while Microsoft Word counted 1810 in both cases as it should be (as a failsafe for AI reformatting where "add paragraph breaks" makes the AI to sometimes change a few words... So this does not work to solve that case).

  • If there is a paragraph break between words with no space, or another special character replacing a space, the count will be off (e.g. protected space or American EM-dash which can have a space on each side — which would then add a word — or no space at all—which would deduct a word).
  • depending on your use case, that might not matter (is your text too long/short?)
  • But it will matter a lot if you need a 100% accurate word count to see if any AI edits have messed with abbreviations, names, technical terms, important small details or Speech-to-Text errors, because you can't see if it was just the formatting that changed the word count or if words have actually been removed/added.
1 Like

Thank you for your feedback and thoughts! Yeah - I designed the snippet as is to serve our specific use case where we send sms messages with a max of 180 characters and no paragraph breaks.

1 Like