Java Reference
In-Depth Information
print(msg1);
print(msg2);
print(msg3);
print(msg4);
It's here and now.
He said, "He is happy."
It's here and now.
He said, "He is happy."
Unlike Java, a string literal in Nashorn can be written in mutiple lines. You need
to use a backslash at the end of the line as the continuation character. Notice that the
backslash and the line terminator are not part of the string literal. Here is an example that
writes the string literal, Hello World! in three lines:
// Assigns the string, Hello world!, to msg using a multi-line string
literal
var msg = "Hello \
world\
!";
print(msg);
Hello world!
If you want to insert a newline character in a multiline string literal, you will need to
use the escape sequence \n as follows. Notice that I have placed the beginning and last
quotes at a separate line that makes the multiline text more readable:
// Uses a multi-line string with embedded newlines
var lucyPoem = "\
STRANGE fits of passion have I known:\n\
And I will dare to tell,\n\
But in the lover's ear alone,\n\
What once to me befell.\
";
print(lucyPoem);
STRANGE fits of passion have I known:
And I will dare to tell,
But in the lover's ear alone,
What once to me befell.
 
Search WWH ::




Custom Search