JS Multi-line string

Source: Internet
Author: User

The most basic practice is to:

JS Code
    1. var str = "111\n222\n333";


But this is not good typesetting. JavaScript itself supports the "\" of the segmentation method, so you can write:

JS Code
    1. var str = "111\n\
    2. 222\n\
    3. 333 ";


But still uncomfortable, no one added a backslash. It is suggested that XML constructs are used, but editors with syntax highlighting are often confused by this notation.

An expert is everywhere, someone actually uses annotations. Personally think this is the most convenient. I changed it a bit:

JS Code
  1. Function.prototype.getMultiLine = function () {
  2. var lines = New String (this);
  3. Lines = lines.substring (Lines.indexof ("/*") + 3, Lines.lastindexof ("*/"));
  4. return lines;
  5. }
  6. var ffff = function () {
  7. /* 
  8. Zhang San to pour water <br/>
  9. <strong> God! </strong>
  10. */
  11. }
  12. document.write (Ffff.getmultiline ());


This is a bit more, but it's worth it to keep multiple lines of text intact.

JS Multi-line string

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.