Forum Academy Marketplace Showcase Pricing Features

Count Words of text returned from an API

Hope someone can help with this problem I’ve been trying to solve all day.

I am trying to count the number of words returned from the text result of an external API. Then once the words are counted, I want to deduct that amount from the users “Credits”. I also use this text result from the API to update the state of a multi line input.

I’ve tried a couple of the word count plugins and have been close to solving this but neither of the plugins are working as required. An example is here: 🎛 New plugin - theCountable (now free) - #82 by ashley.russell77

My workflow would look something like this:

InputA > Sent to API > Result of API updates state of InputB > Words counted > Change thing (user credits) = credits - words counted.

The Words counted part is what I’m really stuck on right now.

Any suggestions would appreciated.

Make changes to [user], set credit field to This User's credits - Result of API's [text string]:split by (space):count?


Bro… I have no idea what that does but it worked! I can’t thank you enough.

What exactly is it the split thing doing in this expression?

1 Like

If you have a single text string AKA your paragraph the API returned, when you do :split by it turns it into a list of texts splitting by whatever character you want (in your case a space), now that it’s a list you can just count them by doing :count

If you needed to filter out “a” “to” “from” or whatever you don’t want to count as a word you can filter those out too before the count if needed

1 Like

All makes sense and so simple in the end, thank you again.

1 Like

Good simple answer - but if you need more sophistication, deal with unicode languages, emojis, deal with stray punctuation (eg don’t count hyphens, commas, etc as words), ie just want more than split by space - try

Full disclosure - it’s my commercial plugin but I just did some fixes on it to deal with emojis.

1 Like