indexOf with text

Moderators: Disciple, zlovatt

Post Reply
rainjam
Posts: 4
Joined: April 4th, 2008, 4:28 am

me again. I'm trying to use a single text layer to create subtitles. The sourceText property has this code (there's a null object called Controller with a slider to control which title shows):

Code: Select all

a = ["Title1", "Title2", "Title3 is a bit longer\r\nso it needs to wrap around"];
n = Math.floor(thisComp.layer("Controller").effect("TextNo")("Slider"));
a[n]
I now want to change the position of the text layer based on whether the text is wrapping to two lines or not. The obvious thing seems to be to use something like

Code: Select all

v = thisComp.layer("TitleText").text.sourceText.indexOf("\r\n");
- if v isn't -1, it's on two lines. However, this doesn't seem to work: it comes out as 1 whether the text is on two lines or not. Any ideas?

EDIT: ...sourceText.indexOf("longer") seems to work for those examples (-1 for n=0 or n=1, 16 for n=2), so it's something to do with the \r\n part. I've tried enclosing that bit in single quotes - ' - and escaping the backslashes with another backslash, but that doesn't work...

Cheers

Nick
Paul Tuersley
Posts: 704
Joined: June 5th, 2004, 7:59 am
Location: London, UK

It works if you change "\r\n" to "\r"

Paul
Dan Ebberts
Posts: 320
Joined: June 26th, 2004, 10:01 am
Location: Folsom, CA
Contact:

You can also do it this way:

thisComp.layer("TitleText").text.sourceText.indexOf(String.fromCharCode(13));

Dan
rainjam
Posts: 4
Joined: April 4th, 2008, 4:28 am

Cheers fellas!
Post Reply