-
AE expression – split text in 2 seperate equal text lines
Hey,
I would love to have some assistance – I have one line of source text, and I want to use that text to create 2 different text layers that split the original text as equal as possible. For example:
1. one layer that is the input text: “Once upon a time there was a princess”
2. one layer that shows the first half of the sentence: “Once upon a time”
3. another layer that shows the second half of the sentence: “there was a princess”I’m not very good with coding but I was able to build something according to previous threads I’ve read and came up with expressions below. But I do have a couple of questions:
A. Is there a better way to do it?
B. If my input text has only one word, how can make the first text layer show that word and leave the second text layer empty?Hope I made myself clear,
Thanks in advance,
/RoyFor the first half of the text:txt = thisComp.layer("TextBox").text.sourceText;
n = Math.round(txt.length/2);
for (i = n; i > 0; i--) if (txt[i] == " ") break;
txt.substring(0,i)For the second half of the text:
txt = thisComp.layer("TextBox").text.sourceText;
n = Math.round(txt.length/2);
for (i = n; i > 0; i--) if (txt[i] == " ") break;
txt.substring(i+1)