javascriptformattingphotoshop-scriptecma

Text on multiple lines without spaces as string literals


I want to be able to create a variable to hold several lines of text which is then created in Photoshop. My code that creates the text works fine. But I've a problem with my code formatting:

var content = "Gwen\r\
               is\r\
               bananas!\r";

However, after I process the text it comes out as this:

Gwen is Bananas! text

Notice the introduction of the whitespace on the second and third line. I don't want to have to format my code on the left like this to remove the string literal spaces.

var content = "Gwen\r\
is\r\
bananas!\r";

In my code, how can I break up/format the text over several lines without having to left justify the text? Avoiding introducing any further whitespace characters?

text over several lines with no extra whitespaces


Solution

  • I have a solution for you. You can use template literals. This solution include placing backticks `. One before the string and one at the end of String. Here's the code:

    var content = `Gwen
    is
    bananas!`;
    

    You can also use string concatenation by applying + after each line. Here's the code:

    var content = "Gwen" +
    "is" +
    "bananas!";
    

    Note: You can use single quotes too.