How can I get the number of word in a text layer?

Find out why the . goes before the /

Moderator: Paul Tuersley

Post Reply
wheelz13
Posts: 3
Joined: April 18th, 2017, 11:47 pm

Hey there,

Currently, I can count characters with this:

Code: Select all

myText = text.sourceText;
myText.length
What I really need is a way to count the number of words within a text layer.

Is this possible?

Thanks in advance! :-)
runegan
Posts: 22
Joined: November 4th, 2016, 3:18 pm
Contact:

There is probably a more accurate way to to this is, but this will be accurate most of the time:

Code: Select all

function getNumWords( string ) {

  // Split the string where there is spaces, then count the array length
  return string.split( ' ' ).length
}
wheelz13
Posts: 3
Joined: April 18th, 2017, 11:47 pm

Thanks!
Post Reply