Expressions/Scripts/Presets

Moderator: Paul Tuersley

 
wheelz13
Topic Author
Posts: 3
Joined: Tue Apr 18, 2017 11:47 pm

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

Tue Apr 18, 2017 11:56 pm

Hey there,

Currently, I can count characters with this:

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: Fri Nov 04, 2016 3:18 pm
Contact:

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

Wed Apr 19, 2017 5:09 am

There is probably a more accurate way to to this is, but this will be accurate most of the time:
function getNumWords( string ) {

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

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

Wed Apr 19, 2017 2:19 pm

Thanks!

Who is online

Users browsing this forum: No registered users and 2 guests