{"id":1010,"date":"2013-11-11T18:50:16","date_gmt":"2013-11-11T23:50:16","guid":{"rendered":"http:\/\/osric.com\/chris\/accidental-developer\/?p=1010"},"modified":"2013-11-11T18:50:16","modified_gmt":"2013-11-11T23:50:16","slug":"converting-lines-to-a-list-in-coldfusion","status":"publish","type":"post","link":"https:\/\/osric.com\/chris\/accidental-developer\/2013\/11\/converting-lines-to-a-list-in-coldfusion\/","title":{"rendered":"Converting lines to a list in ColdFusion"},"content":{"rendered":"<p>I&#8217;m so used to dealing with comma-delimited lists in ColdFusion that I would sometimes take a data file that had one item per line and replace the newline characters with commas.<\/p>\n<p>It&#8217;s easy to use the carriage return [chr(13)] and line feed [chr(10)] characters as list delimiters, though, and remove the intermediary step. Here&#8217;s a quick example:<\/p>\n<pre><code>&lt;cfsavecontent variable=\"data\"&gt;\r\nthis\r\nis\r\na\r\nlist\r\nwith\r\none\r\nword\r\nper\r\nline\r\n&lt;\/cfsavecontent&gt;\r\n\r\n&lt;cfoutput&gt;\r\n    &lt;ol&gt;\r\n        &lt;cfloop list=\"#data#\" delimiters=\"#chr(13)##chr(10)#\" index=\"line\"&gt;\r\n            &lt;li&gt;#line#&lt;\/li&gt;\r\n        &lt;\/cfloop&gt;\r\n    &lt;\/ol&gt;\r\n&lt;\/cfoutput&gt;<\/code><\/pre>\n<p>Which produces the following:<\/p>\n<ol>\n<li>this<\/li>\n<li>is<\/li>\n<li>a<\/li>\n<li>list<\/li>\n<li>with<\/li>\n<li>one<\/li>\n<li>word<\/li>\n<li>per<\/li>\n<li>line<\/li>\n<\/ol>\n<p>(I can&#8217;t believe I didn&#8217;t think of this until today!)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>You can use the delimiter attribute of ColdFusion list methods to turn a multi-line data set into a list of lines.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[349,207],"class_list":["post-1010","post","type-post","status-publish","format-standard","hentry","category-coldfusion","tag-coldfusion","tag-list"],"_links":{"self":[{"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/posts\/1010","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/comments?post=1010"}],"version-history":[{"count":4,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/posts\/1010\/revisions"}],"predecessor-version":[{"id":1015,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/posts\/1010\/revisions\/1015"}],"wp:attachment":[{"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/media?parent=1010"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/categories?post=1010"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/tags?post=1010"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}