Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to create a multiline string?

I´m trying to create a multiline string in Google Apps Scrtip, something like this in Javascript:

var temp = \`Hello
             World!\`;

I have a text that I want to analyze but I don't want to pre-process it.

Is it possible?

like image 535
jhrs21 Avatar asked Nov 08 '16 12:11

jhrs21


2 Answers

If, for example, you had a real long string that extended out past the right margin in the code editor, and you wanted to put it on multiple lines in the editor so that you don't need to scroll to the right to read it, but still want the string to be analyzed as one long string, then you can use:

var a = 'some text\
 more text here\
 third line.';

The above text in the variable a will print as one line.

If you are using V8, then you can use commas at the end of each line.

var a = 'some text,
 more text here,
 third line.';

If you want to cause the string to wrap, in something like an email, or a dialog box, you can use the non-printing newline control characters \n

var t = 'first line \nsecond line \nthird line';

The above string in the variable t will print on three lines.

Note that I did not put any space after \n or the next line would start with a space.

If you are using HTML, then you can use <br>

like image 179
Alan Wells Avatar answered Nov 05 '22 05:11

Alan Wells


It's now possible to use the V8 runtime for google scripts.

This allows you to use the javascript multi-line strings in your google scripts.

Here's how to enable the V8 runtime.

like image 23
jpihl Avatar answered Nov 05 '22 05:11

jpihl