ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

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

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Adirai Maji
I want an expression to find a character's No.of & Place of Occurance?
on Mar 10, 2020 at 5:34:33 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);
txt.substr(0,letter);


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"
}else{
currentLetter;
}


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


Return to posts index

Andrei Popa
Re: I want an expression to find a character's No.of & Place of Occurance?
on Mar 10, 2020 at 8:43:55 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;
stringToSearch.split(specificLetter).length-1


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

specificLetter = "L";
stringToSearch = thisComp.layer("HELLO").text.sourceText.toUpperCase();
stringToSearch.split(specificLetter.toUpperCase()).length-1


Andrei
My Envato portfolio.


Return to posts index

Adirai Maji
Re: I want an expression to find a character's No.of & Place of Occurance?
on Mar 13, 2020 at 6:29:56 am

Thank you so much. It's really helpful

==================================================================================================
Thanks in Advance...

- Adirai Maji


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2020 CreativeCOW.net All Rights Reserved
[TOP]