Multiline Strings [JS 1.6]


/ Published in: JavaScript
Save to your folder(s)

*Requires JavaScript 1.6 or higher*

Syntax: `mutilineString(_ processing instruction_)`

**Note**: The string processing instruction cannot include ?> in the string and does not support escaped characters (ie. \u0000)

Example:

var string =
LEFT-ANGLE-BRACKET?string foo
bar
baz?RIGHT-ANGLE-BRACKET;
mutilineString(string) == "foo\nbar\nbaz"

Due to a problem with Snipplr, I can't put processing instructions in the comments. Replace LEFT-ANGLE-BRACKET with < and replace RIGHT-ANGLE-BRACKET with >


Copy this code and paste it in your HTML
  1. if (this.XML && XML.ignoreProcessingInstructions == true)
  2. XML.ignoreProcessingInstructions = false;
  3.  
  4. function multilineString(spi) { // spi === <?string ...?>
  5. if (typeof spi != "xml")
  6. throw new TypeError(arguments.callee.name);
  7. return spi.toXMLString()
  8. .replace(/^<\?string ([\s\S]*)\?>$/i, "$1")
  9. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.