Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Forums Adobe After Effects Expressions I want an expression to find a character’s No.of & Place of Occurance?

  • I want an expression to find a character’s No.of & Place of Occurance?

  • Adirai Maji

    March 10, 2020 at 5:34 am

    Okay the title won’t explains a lot. Let me explain it here….

    I’ve a text layer having text as “HELLO” in it. And I applied the following expression to animate the text in it by a slider value.

    txt = text.sourceText;
    typeSlider = effect("Slider Control")("Slider");
    letter = Math.round(typeSlider);

    So each time I increase the slider value each letter getting revealed one by one.

    This is what I want to do. I want to check every new letter that revealing, If it’s a specific letter I want to know how many times it occured. For reference I’ve created an empty text layer and applied the following code to the sourceText property

    slider = Math.round(thisComp.layer("HELLO").effect("Slider Control")("Slider"));
    lastLetter = slider-1;
    string = thisComp.layer("HELLO").text.sourceText
    currentLetter = string.charAt(lastLetter);
    if (currentLetter == "L"){
    "The Letter is L"

    So according to the code in the second text layer. It only reveals the last letter of first text layer. If the slider value is 2 the first Text layer only shows “HE” and the second Text layer shows “E”.

    when the slider value turns 3 the first Text layer shows “HEL” and the second Text layer shows “The Letter is L” because the last letter is L so it check the if condition and reveal the string inside if condition.

    But I want to know how many times the letter “L” is in the part of the first Text layer. I want to have a variable that increases itself by the number of occurance of letter “L”. So the variable must be 0 at first and when it sees the “L” at first time it should increased to 1. and when the slider values goes 4 (“HELL”) the variable should increaed to 2. and it should remember the slider value with it. Any idea???

    Thanks in Advance…

    – Adirai Maji

  • Andrei Popa

    March 10, 2020 at 8:43 am

    Not really sure what you want but this may be a solution; On the second layer add this as sourceText

    specificLetter = "L";
    stringToSearch = thisComp.layer("HELLO").text.sourceText;

    You can make this case-insensitive(ignore differenced between a and A) like this:

    specificLetter = "L";
    stringToSearch = thisComp.layer("HELLO").text.sourceText.toUpperCase();

    My Envato portfolio.

  • Adirai Maji

    March 13, 2020 at 6:29 am

    Thank you so much. It’s really helpful

    Thanks in Advance…

    – Adirai Maji

Viewing 1 - 3 of 3 posts

Log in to reply.

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