0

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.

timkado
  • 1,922
  • 2
  • 17
  • 27
  • 1
    You would need to use newlines (\n) and probably tabs (\t), and figure out why on earth you would need such a string, and if there really aren't better approaches to the problem. – adeneo Dec 03 '12 at 00:07
  • I have absolutely no idea what language is "C# in Javascript". From the looks of it, this is javascript but you're using tripple quotes? – Eudis Duran Dec 03 '12 at 00:07
  • Tripple quotes are always cool ? – adeneo Dec 03 '12 at 00:09
  • What language is that? `!` comments and tripple quotes don't validate in JavaScript. – Šime Vidas Dec 03 '12 at 00:11
  • OK... would it be better to replace all the variables with some tag that I could later exchange with regex? – timkado Dec 03 '12 at 00:11
  • ok removed the """ - was just a desperate attempt to make it work :) – timkado Dec 03 '12 at 00:14

1 Answers1

3
  • \ - 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' +
'!!!' +
...
Community
  • 1
  • 1
Michael Malinovskij
  • 1,422
  • 8
  • 22