Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions && is referencing only part 2

  • && is referencing only part 2

    Posted by Scott Mcgee on June 28, 2017 at 2:28 pm

    I’ve reached the end of project and realised that I haven’t taken into account. If my colleagues type in Weekdays/Weeknights 7.30pm & 8.30pm, the text goes over the edge of my border I’ve created.

    a = text.sourceText;
    if (a.indexOf (“Weekdays” && “.30pm &”) != -1){
    “Weekdays” +”\r”+ a.substr(9,25)
    }
    else if (a.indexOf (“Weeknights” && “.30pm &”) != -1){
    “Weeknights” +”\r”+ a.substr(12,25)
    }
    else
    a;

    but it seems to ignore the first word and only looks at “.30pm &”, which I don’t want it to. Any ideas?

    Scott Mcgee replied 9 years, 1 month ago 1 Member · 3 Replies
  • 3 Replies
  • Scott Mcgee

    June 28, 2017 at 2:35 pm

    I’m an idiot once again.

    For anyone having issue to find multiple words using indexOf

    a = text.sourceText;
    if (a.indexOf ((“Weekdays”) && (“.30pm &”)) != -1){
    “Weekdays” +”\r”+ a.substr(9,25)
    }
    else if (a.indexOf ((“Weeknights”) && (“.30pm &”)) != -1){
    “Weeknights” +”\r”+ a.substr(12,25)
    }
    else
    a;

  • Scott Mcgee

    June 28, 2017 at 2:43 pm

    Nope I was too quick to respond

    a = text.sourceText;
    if (a.indexOf ((“Weekdays”) && (“.30pm &”)) != -1){
    “Weekdays” +”\r”+ a.substr(9,25)
    }
    else if (a.indexOf ((“Weeknights”) && (“.30pm &”)) != -1){
    “Weeknights” +”\r”+ a.substr(12,25)
    }
    else
    a;

    if I type “Weeknights 7.30pm & 8.30pm”, the result ends up

    Weekdays
    s 7.30pm & 8.30pm

  • Scott Mcgee

    June 28, 2017 at 3:27 pm

    Not the way I wanted to write it, but this works

    input = text.sourceText;
    result = text.sourceText;
    for (var i = 1; i <= 24; i++){
    if (input.indexOf(“Weekdays “+i+”.30pm &”) > -1){
    result = input.substr(0,8) +”\r”+ input.substr(9,25);
    break;
    }
    else if (input.indexOf(“Weeknights “+i+”.30pm &”) > -1){
    result = input.substr(0,10) +”\r”+ input.substr(11,25);
    break;
    }
    }
    result

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