0

Possible Duplicate:
How to create multiline strings

I have a lot of strings that I want to put in variables, but there is line breaks that aren't accepted.

Firefox says "Unterminated string literal" when I write :

var a="foo
bar";

Is there a way to write my strings without removing the line breaks manually?

Community
  • 1
  • 1
user1365010
  • 3,185
  • 8
  • 24
  • 43

2 Answers2

1

If this is not acceptable:

var a="foo" +
"bar";

Or as @minitech (the new mod) suggested:

var a="foo \
bar";

Then the answer is no.

gdoron
  • 147,333
  • 58
  • 291
  • 367
0

Is this script generated dynamically by a web server?

If so, this web server will need to convert line breaks to the \n escape sequence instead. You'll also have the same issue with other reserved characters, such as the backslash and double-quotes.

Some languages allow you to literally write a string constant (such as the @ prefix in C#), however Javascript has no such feature standard, thus certain characters must be escaped.

Mike Christensen
  • 88,082
  • 50
  • 208
  • 326