ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

find and replace - to + and vice versa

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Dennis Cheung
find and replace - to + and vice versa
on Oct 31, 2019 at 6:26:29 pm

Hello

I've gone through the forum looking for a way to find and replace the "+" or "-" symbol in the text layer above and switch to its opposite value. For example: if layer 1 shows "+7," layer 2 should be "-7," or layer 1 shows "-10," layer 2 should be "+10."

this code I have isn't working:
thisComp.layer(index-1).text.sourceText.replace(/\u002B/gi,"-").replace(/\u002D/gi, "+");

Thanks for your time everyone and thanks in advance for any and all solutions


Return to posts index

Dan Ebberts
Re: find and replace - to + and vice versa
on Oct 31, 2019 at 7:26:31 pm

Will it be one or the other (or neither)? If so, this should work:


txt = thisComp.layer(index-1).text.sourceText;
if (txt.indexOf("-") > -1)
txt.replace(/\u002D/gi, "+")
else
txt.replace(/\u002B/gi,"-");


Dan



Return to posts index

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