Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Is there an expression that looks at the first character of a text layer?

  • Is there an expression that looks at the first character of a text layer?

    Posted by Gietr Zula on November 18, 2020 at 2:38 pm

    I need an expression that changes the value of the position of a layer based on the first character of a text layer. For example if the frst character is “A” the position is 0,100. If the first letter is “B” the position is 0,200 etc.

    Could anyone please help? Thanks in advance!

    Giet

    Matt Volp replied 5 years, 9 months ago 2 Members · 1 Reply
  • 1 Reply
  • Matt Volp

    November 18, 2020 at 4:10 pm

    You could use

    str.charAt(0)

    where the argument, in this case, ‘0’, is the character of the string you want to look at. So something like this:

    str = text.sourceText;

    firstLetter = str.charAt(0);

    if (firstLetter === "A") {

    [0,100]

    } else if (firstLetter === "B") {

    [0,200]

    }

    If you wanted to do it programmatically, perhaps something like this would work:

    str = text.sourceText;

    firstLetter = str.charAt(0);

    letters = ["A","B","C","D","E","F","G","H"];

    for (i = 0; i < letters.length; i++) {

    if (firstLetter === letters[i]) {

    y = (i+1) * 100;

    break;

    }

    }

    [0,y];

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy