timkado
timkado

Reputation: 2052

multiline string concatenation - ignore escape chars

is there a suppress escape chars in Javascript similar to the @ in C# ? I have to assemble a sting like below - however Im having problems with the multi-line layout and some of the characters in the string. How would one concatenate such a string in Javascript?

my attempt to concatenate my string in JAVASCRIPT:

  var idfTEXT_ROOM = "
    ! " + this.Name +"
    ! -------------
    Zone,
    " + this.Name + ",           !- Name
    " + this.DirRelNorth + ",    !- Direction of Relative North {deg}
    0,                       !- X Origin {m}
    0,                       !- Y Origin {m}
    0,                       !- Z Origin {m}
    1,                       !- Type
...

Of course like that it throws an "Uncaught SyntaxError: Unexpected string" error.

Upvotes: 0

Views: 2339

Answers (1)

Michael Malinovskij
Michael Malinovskij

Reputation: 1422

  • \ - regular escape, if you need quote in your string just type \'
  • \n - new line
  • \t - tab

For multiline strings here are different options for you.

Im always using this method:

'Hello Javascript' + 
'world' +
'!!!' +
...

Upvotes: 3

Related Questions