• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

Community Beginner ,
May 19, 2020 May 19, 2020

Copy link to clipboard

Copied

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.

TOPICS
Expressions

Views

3.3K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Explorer , May 26, 2020 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
...

Votes

Translate

Translate
LEGEND ,
May 19, 2020 May 19, 2020

Copy link to clipboard

Copied

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

 

Mylenium

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 22, 2020 May 22, 2020

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 26, 2020 May 26, 2020

Copy link to clipboard

Copied

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

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 27, 2020 May 27, 2020

Copy link to clipboard

Copied

You're save my life. This is what I was looking for:

"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, " ");

 

Thank you

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 02, 2022 Feb 02, 2022

Copy link to clipboard

Copied

Hi,
I try it and it works! but it works only in English! I tried in Thai it doesn't work for me TT.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 31, 2023 Aug 31, 2023

Copy link to clipboard

Copied

LATEST

What if I need to split one line into two. Right now I have a line that splits in one line per word.

thisComp.layer("MAIN TEXT").text.sourceText.split(" ").join("\r");

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines