Adobe After Effects Expressions Forum
Trying to find a specific word and see the priority in the text layer.
Trying to find a specific word and see the priority in the text layer.
by Kyung Ko on Mar 11, 2020 at 1:42:39 pm

Hello,
I'm trying to see if the specific word exists and see the order number of it.

Example
Here's the text layer: "Apple, Grape, Blueberry"
Here's the result I would like to get: Apple = 1, Grape =2, Blueberry =3

If the text layer is like this: "Grape, Blueberry, Apple"
Then, here's the result that should be: Apple = 3, Grape = 1, Blueberry = 2

Thanks so much!


Re: Trying to find a specific word and see the priority in the text layer.
by Tomas Bumbulevičius on Mar 11, 2020 at 2:18:08 pm

Hey Kyung,

here is the idea:
1. First layer in the comp - reference.
2. Second layer - new order.
3. Third - result.

This can be changed of course, but for better visual clue, I made it this way.


Seems to do what it is suppose to.

refText = thisComp.layer(1).text.sourceText
curText = thisComp.layer(2).text.sourceText

refArray = refText.split(",");
curArray = curText.split(",")

res = "";

for(i=0; i<refArray.length; i++){

refText = refArray[i];
for(j=0; j<curArray.length; j++){
curText = curArray[j];
if (refText == curText){
curIndex = j;
}
}
res = res + refText + "=" + (curIndex+1).toString() + ",";
}

res



Find out more:
After Effects Tutorials: motion design, expressions, scripting.
Boxer - Dynamic Text Boxes Template with a Live Preview



Re: Trying to find a specific word and see the priority in the text layer.
by Kyung Ko on Mar 11, 2020 at 2:27:51 pm

Thanks so much! This should work for my purpose. Really appreciate it!


Re: Trying to find a specific word and see the priority in the text layer.
by Tomas Bumbulevičius on Mar 11, 2020 at 5:46:48 pm

Kyung - just one thing to clarify - expression above should be added into 3rd layer's (result) Source Text.

Find out more:
After Effects Tutorials: motion design, expressions, scripting.
Boxer - Dynamic Text Boxes Template with a Live Preview



Re: Trying to find a specific word and see the priority in the text layer.
by Kyung Ko on Mar 12, 2020 at 3:16:01 pm

Yep, I figured. Thanks Tomas!





© CreativeCOW.net