Skip to main content
cris.o
Participant
April 1, 2021
Answered

Changing character colors in a string, could expressions help?

  • April 1, 2021
  • 1 reply
  • 413 views

Hello all -

I am a complete newbie when it comes to After Effects, but here to learn!

I have a long string of characters in the following format, which I created a ticker with (championship standings):

1. #30 Rcraft - 124    2. #112 Varns - 78    3. #28 Riley - 64    4. #3 Bondy - 58

I can't seem to figure out a way to change the color or font format of the "#xx" number. The unfortunate part is that sometimes it's "#x", other times "#xx", and other times "#xxx". Ideally, I would like to find an expression/script to do this, as the string will change weekly, so it would save me from manually selecting and changing the color over and over again.

Is this even possible? Thank you for your help!

This topic has been closed for replies.
Correct answer Dan Ebberts

Try this: Add a Fill Color animator to your text, and add an Expression Selector to the animator. Then add this expression to Amount property of the Expression Selector:

txt = text.sourceText.value;
idx = textIndex;
val = 0;
for (i = textIndex; i > 0; i--){
  if (txt[i-1] == "#"){
    val = 100;
    break;
  }else if(txt[i-1] == " "){
    val = 0;
    break;
  }
}
val

It may not be exactly what you're after, but it should give you the idea of how to get there.

1 reply

Dan Ebberts
Community Expert
Dan EbbertsCommunity ExpertCorrect answer
Community Expert
April 1, 2021

Try this: Add a Fill Color animator to your text, and add an Expression Selector to the animator. Then add this expression to Amount property of the Expression Selector:

txt = text.sourceText.value;
idx = textIndex;
val = 0;
for (i = textIndex; i > 0; i--){
  if (txt[i-1] == "#"){
    val = 100;
    break;
  }else if(txt[i-1] == " "){
    val = 0;
    break;
  }
}
val

It may not be exactly what you're after, but it should give you the idea of how to get there.

cris.o
cris.oAuthor
Participant
April 1, 2021

Initially, it wasn't working, until I realized my Masks were off. Once I turned them on, it worked like a charm. I even extended it to include the name, which made it look pretty nice.

Thank you so much!!!