Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Using Expression to Check Text String Match

Tagged: 

  • Using Expression to Check Text String Match

    Posted by Roland R. kahlenberg on December 6, 2023 at 12:12 pm

    So, a Text Layer, “Layer Text” has the following Text String –

    Comprehensive Meals
    TODAY ONLY

    When checking if the string has changed, in another layer, I’ve got this Expression –

    const a = thisComp.layer(“Layer Text”).text.sourceText;

    if(a == “Comprehensive Meals” + “\n” + “TODAY ONLY”) {“YES”} else {“NO”}

    I should be getting a result of YES but instead I’m getting a NO. Why?
    I’ve done this ages ago but I seem to have forgotten something critical.
    TIA

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

    December 6, 2023 at 12:30 pm

    You’re using the wrong new line operator. By default, AE uses “\r” rather than “\n” (although “\n” will work as a new line if you output it in a string)

    so the below for me gives me a “YES” instead.

    var a = thisComp.layer(“Layer Text”).text.sourceText;

    if(a == “Comprehensive Meals\rTODAY ONLY”) {“YES”; } else {“NO”; };

    Note that you don’t need to concatenate the strings with the \r operator, you can just use a single string.

  • Roland R. kahlenberg

    December 6, 2023 at 12:36 pm

    AWESOME!!!

    Thanks Tom!!!

  • Tom Morton

    December 6, 2023 at 2:32 pm

    no worries 🙂

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