Creative COW SIGN IN :: SPONSORS :: ABOUT US :: CONTACT US
ADOBE AFTER EFFECTS: ForumAE BasicsAE ExpressionsTutorialsArticlesPodcastsMotion GraphicsTrainingCinema 4D

Replace Text Expression

Cow Forums : Adobe After Effects Expressions
cow
Replace Text Expression
by matthew tully on Jul 23, 2008 at 3:16:42 pm

Howdy,

Problem: I am loading text dynamically from an XML file to write credits for several artists using a script. When I pull the data into AE it keeps introducing a string of escaped code. I can't seem to solve the broken code, but the string it dumps in is always the same, its a unicode value.

Solution(i think): attach an expression to search for the escaped code in Source Text. Replace the unicode with another string of text using if/else.

Questions: Here is loosely what I imagined using. How do I make it search and find just the one string?

if (text.sourceText = "xyz") text.sourceText = "replaced" else (text.sourceText);

right now this code would return "replaced" regardless of what is in the source text. So its totally broken. I understand why, but I don't know how to tell it to find just one string in sourceText. Please help!

Thanks in advance. This forum has helped me so many times!

Respond to this post   •   Return to posts index

cow
Re: Replace Text Expression
by Lloyd Alvarez on Jul 23, 2008 at 3:32:30 pm

try this:

text.sourceText.replace(/something to replace/gi, "what to replace it with")


-Lloyd



http://aescripts.com

Respond to this post   •   Return to posts index

cow
Re: Replace Text Expression
by Lloyd Alvarez on Jul 23, 2008 at 3:34:30 pm

in case you are wondering what the gi stands for:

search (g)lobally for the string and be case (i)nsensitive

http://aescripts.com

Respond to this post   •   Return to posts index


cow
Re: Replace Text Expression
by Dan Ebberts on Jul 23, 2008 at 3:34:36 pm

You should be able to fix the problem in the script, but if not, this expressions should do it:

text.sourceText.replace(/xyz/,"replaced")

Dan



Respond to this post   •   Return to posts index

cow
Re: Replace Text Expression
by matthew tully on Jul 23, 2008 at 4:48:10 pm

Thanks for the tips. Victory!

You guys are awesome!

Do either of you have any good resources for expressions that control text?

Respond to this post   •   Return to posts index

cow
Re: Replace Text Expression
by Dan Ebberts on Jul 23, 2008 at 5:11:45 pm

Any good JavaScript reference will have a section on string methods, which will be very helpful. It should also include a section on "Regular Expressions" (not related to AE expressions) which are used by some of the string methods.

Dan



Respond to this post   •   Return to posts index


cow
Re: Replace Text Expression
by matthew tully on Jul 23, 2008 at 8:47:33 pm

Thanks again Dan!

Respond to this post   •   Return to posts index

<< PREVIOUS THREAD   •   VIEW ALL THREADS   •   PRINT   •   NEXT THREAD >>


FORUMSTUTORIALSMAGAZINEDVDsBOOKSPODCASTSEVENTSSERVICESNEWSLETTERNEWSBLOGS

© CreativeCOW.net All rights are reserved.

[Top]