{"id":18835,"date":"2016-11-22T17:52:09","date_gmt":"2016-11-22T17:52:09","guid":{"rendered":"http:\/\/www.oracletutoring.ca\/blog\/?p=18835"},"modified":"2018-11-14T05:16:29","modified_gmt":"2018-11-14T05:16:29","slug":"web-programming-javascript-how-to-manage-a-multi-line-string","status":"publish","type":"post","link":"https:\/\/www.oracletutoring.ca\/blog\/web-programming-javascript-how-to-manage-a-multi-line-string\/","title":{"rendered":"Web Programming:  JavaScript:  how to manage a multi-line string"},"content":{"rendered":"<h1>The tutor tells a trick for printing long strings with JavaScript.<\/h1>\n<p>Suppose you have a long string, over many lines, that you want to print with JavaScript.<\/p>\n<p>Typically, to print a string, you might assign it to a variable, then print the variable:<\/p>\n<div style=\"font-family:monospace;font-size:120%;color:#449900\">\nvar string_0=&#8221;Getting ready for Christmas&#8230;(and so on)&#8230;&#8221;;<br \/>\ndocument.getElementById(&#8220;div_0&#8221;).innerHTML=string_0;\n<\/div>\n<p style=\"white-space:pre-wrap\"><\/p>\n<p>In my experience, if the program you&#8217;re using puts a line break in the string, that seems okay.  However, JavaScript may not allow an explicit line break in a string variable:<\/p>\n<div style=\"font-family:monospace;font-size:120%;color:#449900\">\nvar string_0=&#8221;Getting<br \/>\nready<br \/>\nfor<br \/>\nChristmas&#8221;; <span style=\"color:#990022\">seems not to work<\/span>\n<\/div>\n<p style=\"white-space:pre-wrap\"><\/p>\n<p>Nonetheless,<\/p>\n<div style=\"font-family:monospace;font-size:120%;color:#449900\">\nvar string_0=&#8221;Getting &#8220;+<br \/>\n&#8220;ready &#8220;+<br \/>\n&#8220;for &#8220;+<br \/>\n&#8220;Christmas&#8230;.&#8221;; <span style=\"color:#990022\"><\/span>\n<\/div>\n<p style=\"white-space:pre-wrap\"><\/p>\n<p>will print as<\/p>\n<div id=\"the_div\"><\/div>\n<p><script src=\"\/..\/javascripts\/string_test_nov22_2016.js\" \/><\/script><\/p>\n<p style=\"white-space:pre-wrap\"><\/p>\n<p>That&#8217;s what I&#8217;ve noticed, anyhow:)<\/p>\n<p>Source:<\/p>\n<p><a href=\"http:\/\/www.w3schools.com\/jsref\/dom_obj_style.asp\">w3schools<\/a><\/p>\n<p>Jack of <a href=\"https:\/\/www.oracletutoring.ca\">Oracle Tutoring by Jack and Diane,<\/a> Campbell River, BC.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The tutor tells a trick for printing long strings with JavaScript. Suppose you have a long string, over many lines, that you want to print with JavaScript. Typically, to print a string, you might assign it to a variable, then &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"more-link\" href=\"https:\/\/www.oracletutoring.ca\/blog\/web-programming-javascript-how-to-manage-a-multi-line-string\/\"> <span class=\"screen-reader-text\">Web Programming:  JavaScript:  how to manage a multi-line string<\/span> Read More &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1713,1855],"tags":[2044,2043],"class_list":["post-18835","post","type-post","status-publish","format-standard","hentry","category-javascript","category-web-programming","tag-how-to-handle-a-long-string-in-javascript","tag-string-over-several-lines-in-javascript"],"_links":{"self":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/18835","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/comments?post=18835"}],"version-history":[{"count":33,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/18835\/revisions"}],"predecessor-version":[{"id":36169,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/18835\/revisions\/36169"}],"wp:attachment":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/media?parent=18835"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/categories?post=18835"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/tags?post=18835"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}