Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Split() expression with If else

  • Split() expression with If else

    Posted by Mac Lad on May 21, 2021 at 2:37 am

    hello guys,

    I have a text layer with below given expression on sourceText property which tries to grab names from the comp which has list of 208 countries name in it. Every country is a precomp and has a respective code and county name on it eg. IND – INDIA.

    id = thisComp.layer("CONTROL").effect("SELECT COUNTRY")("Menu"); 
    c = comp("Country Names").layer(id).name.split("-")[1];

    but my problem starts where the country name like USA are written which only has code in name due to character limitation in design. So I am trying to write an if/else statement which can check based on “-” in name. So names without “-” will be used as written on precomp. I came up with below expression but this won’t work as expected.

    id = thisComp.layer("CONTROL").effect("SELECT COUNTRY")("Menu"); 
    c = comp("Country Names").layer(id).name;
    if(c.split("-")>0){c.split("-")[1]} else {c};

    Thank you!

    이 중광 replied 4 years, 12 months ago 3 Members · 3 Replies
  • 3 Replies
  • Dan Ebberts

    May 21, 2021 at 3:07 am

    Try adding .length to the split array, like this:

    if(c.split("-").length>1){c.split("-")[1]} else {c}; 
  • Mac Lad

    May 21, 2021 at 3:25 am

    Thanks Dan, that works!!! Didn’t knew I can use .length in split …thanks!!!

  • 이 중광 Create COW Profile Image

    이 중광

    May 21, 2021 at 3:58 am
    if (c.split("-")[1] == null) {c} else {c.split("-")[1]};

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