Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions sourcetext: two expressions work well alone, but not together

  • sourcetext: two expressions work well alone, but not together

    Posted by Matthias Schwarz on April 11, 2024 at 12:03 pm

    Hello dear fellows,

    I wrote two lines of code for a source text:

    var txt = value;

    txt.trim(); //removes whitespaces in front of text

    txt.substr(0/37);//limits the string to 37 signs

    Both expressions do what they should do when applied alone, but when I put them together,

    the trim-expression seems not to function- whitespaces in front will not be cutted off. I tried to change to order of the two line as a test, but I still have no clue why does not work properly. I used the clamp-expression in an other situation, but I guess this is a wrong way. Does anyone have an idea to put them together or have a different solution? Thanks you so much!

    Yours, Matthias

    Brie Clayton replied 2 years, 3 months ago 3 Members · 3 Replies
  • 3 Replies
  • Tom Morton

    April 11, 2024 at 12:14 pm

    you’ve got the syntax wrong, each expression works fine on it’s own, but they RETURN a value, they don’t modify the existing value.

    var txt = value;
    txt.trim(); // removes whitespaces in front of text and returns the value - doesn't change the value of "txt" variable
    txt.substr(0/37);//limits the ORIGINAL string to 37 signs and returns it again. Expressions uses this as the last returned value

    Therefore you need to do something like this:

    var txt = value;
    txt = txt.trim(); //removes whitespaces in front of text
    txt = txt.substr(0/37); //limits the string to 37 signs
    txt;

    each expression will now update the value of the “txt” variable. hope that helps!

  • Matthias Schwarz

    April 11, 2024 at 1:30 pm

    Yes, it works! Thank you so much for that help! It´s just mean that the expressions works seperately..I need to code for work and it´s so long ago that I did this. The brain is a sieve…or more precise,

    my brain 🤣

    Yours, Matthias

  • Brie Clayton

    April 11, 2024 at 2:31 pm

    Thank you for solving this, Tom!

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