After Effects Tip: charAt() Expression in After Effects

In this post, I will go over Character At Expression charAt() in After Effects. So without any further ado, let’s dive right in!

Alright, here we are in After Effects. Let me show you what we will be creating.

charAt() in Adobe After Effects

So I have an orange circle in my composition with a white letter U in the center of it and I also have a text layer UKRAMEDIA below the orange circle.

If I change the UKRAMEDIA text to let’s say SERGEI, the white letter inside of the orange circle will automatically change from U to S.

Chaning text in After Effects

So the white letter inside of the orange circle automatically grabs the first letter of the text layer below.

Now if decide to change the text from UKRAMEDIA to another name like ELIJAH, the white letter inside of the orange circle will automatically change from S to E. You get the idea. All of that is possible because of charAt() Expression. Now let me show you how to set this up.

Elijah text change in After Effects

Setting up charAt() Expression

Step 1:

The first thing I am going to do is go inside of the S letter.

S letter After Effects

Step 2: Solo Keyboard Shortcut

Select the Source Text under Text and press S twice on your keyboard to solo it.

Press S twice to solo in After Effects
Step 3: Activate the Expression

ALT+RIGHT CLICK (CMD+RIGHT CLICK on a MAC) on the stopwatch icon next to the Source Text to activate the expression. You should see a white box appear when you do that.

Stopwatch click Activate Expression in After Effects

Step 4: Setting Variables in After Effects

I want a variable for the UKRAMEDIA text layer. So in order to do that, I am going to say nameText, you will be and then I will pick whip to the UKRAMEDIA text layer like so:

Pick whip in After Effects

Then I will keep going and say .text.sourceText;. So I want the source text of that layer. Our Expressions should look like this:

nameText = thisComp.layer(“UKRAMEDIA”).text.sourceText;

nameText = thisComp.layer(UKRAMEDIA).text.sourceText in After Effects

Next, I’ll do this Character At Expression. It is pretty simple.

Step 5: Applying charAt() Expression

So in a separate line, I am going to say nameText.charAt(). If I leave it as it is, this expression will automatically grab the first letter of my text, which is UKRAMEDIA at the moment. So I’ll go ahead and leave it the way it is because I want it to automatically grab the first letter of my text layer. However, you can do more than that.

Applying charAt() Expression in After Effects

You may remember me talking about the index in the previous posts. The way index work is you can tell which letter you want to grab inside of the chartAt parentheses.

So let’s say we want the letter R from the UKRAMEDIA text layer. The letter R will be index 2 because we start counting from 0 not 1. So inside of our chartAt() I will say I want the index 2 like so:

nameText = thisComp.layer(“UKRAMEDIA”).text.sourceText;


Index After Effects Expressions

As I do that, the white letter inside of the orange circle will automatically switch to the letter R.

Switching to letter R in After Effects

What if let’s say I wanted to grab the first and the last letters of the UKRAMEDIA text layer? How would I do that? Let me show you.

First, let’s change the index number to 0 like so:


Next, I’m going to say nameText.charAt(0) + and I’ll just copy the same expression nameText.charAt(); but instead of me typing index 8 inside of the charAt parenthesis because 8 is the last index number in the word UKRAMEDIA.

Remember, we start with 0, so the UKRAMEDIA text layer count will look like this: 0, 1, 2, 3, 4, 5, 6, 7, 8. So the last letter is 8. But what if the next word is much shorter than 8? If type 8 inside of the parenthesis then the number would be a different index if the text changed.

So to get the last letter of a text layer we need to type nameText.length-1 inside of the charAt parenthesis. It will grab the last letter of any word you type. Short or long. It doesn’t matter.

nameText.charAt(0) + nameText.charAt(nameText.length-1);

Let’s click out of the white box to test it out and see if our expression is working properly.

Grab First and Last word of charAt expression in After Effects

Looks like the two white letters inside of our orange circle are UA. That means our expression is working properly. That is how simple it is to set up a charAt() Expression.

I hope you found this post useful. If you would like to learn more about Expression and how it can speed up your workflow in After Effects, check out my Learn After Effects Expressions Course.

About the author:

Sergei Prokhnevskiy

Sergei Prokhnevskiy is a Charlotte, NC based motion graphics designer, an online tutor, an entrepreneur, and Adobe MAX Master Speaker. Sergei is known for his quick and practical After Effects tips and tricks on YouTube, where he generated well over 6 million views on his tutorials. He has authored an online video course on After Effects Expressions and developed scripts for After Effects. He is also a former senior motion graphics designer at Fox Sports where he worked on graphics for NFL, Super Bowl, MLB, World Series, College Football, NASCAR, Women’s World Cup, and NASCAR Race Hub. He is very passionate about learning and teaching others.


Over 100,000 downloads & counting!

These 5 After Effects tools will seriously speed up your workflow and save you hours of wasted time. More than that, they could be the difference between being able to complete a project on time or not!