Activity › Forums › Adobe After Effects Expressions › Expression to clamp the text length and add “…” to the end if over value
-
Expression to clamp the text length and add “…” to the end if over value
-
Shane Starnes
February 27, 2023 at 9:57 pmHey guys, I’m working on a project that will take input from various users for the same project. Some of these users may use text that will extend beyond the visual bounds of the text field, and I’d like to stop it from moving/scaling beyond that field, and also add “…” to the end to keep it visually appealing. Automatic scaling with sourceRecAtTime is not an option here. Here’s the expression I’ve used so far on the Source Text Property:
text.sourceText.substr(0,36);
if (text.sourceText.length >= 35){
text.sourceText + “…”;};
It adds the ellipsis where it should be, but doesn’t clamp the text length. I’m stumped. Any ideas?
-
Dan Ebberts
February 27, 2023 at 10:19 pmSomething like this:
txt = text.sourceText.value;
if (txt.length > 36)
txt.substr(0,35) + "..."
else
txt -
Shane Starnes
March 14, 2023 at 9:29 pmHi Dan,
Thank you for your response, and I apologize for my late reply. This works perfectly for my use case. So happy to have received your input on this matter. You’re a legend! 😃
Regards, Shane
Reply to this Discussion! Login or Sign Up
Log in to reply.