Skip to main content
Participating Frequently
May 19, 2020
Answered

Two or more lines of text to one line in another comp

  • May 19, 2020
  • 1 reply
  • 4328 views

Hi to All. I have an issue. I have a text layer which may consist of one, two or more lines breacked by enter. When I'm adding expression to another layer it getting just first line of main text layer, I want it getting whole text no matter how many lines it have and build one line from it.
Can anyone help me with that. And Thank you in advance.

Correct answer gregoryw80731704

This should get you all the text no matter how many lines it's on.

comp("SubjectInfo").layer("PropertyName").text.sourceText

 

 Or are you trying to put all the lines on to one line? This is changing any carriage return with a space

comp("SubjectInfo").layer("PropertyName").text.sourceText.replace(/\r/g, " ");

 

 The way you were trying to do it you would need a for loop for the amount of lines and a += to concatenate all the results which would look something like this

var mainText = comp("SubjectInfo").layer("PropertyName").text.sourceText.split(/\r/g);
var printOut = "";

for(i = 0; i < mainText.length; i++){
	
	printOut += mainText[i]+" ";
}
printOut

 

1 reply

Mylenium
Legend
May 20, 2020

Without any idea about what expression you use we cannot know.

 

Mylenium

CostazAuthor
Participating Frequently
May 22, 2020

Yes, sorry, here is my expression, but it's simple and it will work only with 2 lines.

a=comp("SubjectInfo").layer("PropertyName").text.sourceText.split('\r')[0];
b=comp("SubjectInfo").layer("PropertyName").text.sourceText.split('\r')[1];
a+" "+b

gregoryw80731704Correct answer
Inspiring
May 26, 2020

This should get you all the text no matter how many lines it's on.

comp("SubjectInfo").layer("PropertyName").text.sourceText

 

 Or are you trying to put all the lines on to one line? This is changing any carriage return with a space

comp("SubjectInfo").layer("PropertyName").text.sourceText.replace(/\r/g, " ");

 

 The way you were trying to do it you would need a for loop for the amount of lines and a += to concatenate all the results which would look something like this

var mainText = comp("SubjectInfo").layer("PropertyName").text.sourceText.split(/\r/g);
var printOut = "";

for(i = 0; i < mainText.length; i++){
	
	printOut += mainText[i]+" ";
}
printOut