Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I write a newline in a string in ColdFusion?

Currently I'm putting newlines in strings through one of these two methods:

<cfset someStr="This is line 1" & Chr(10) & "This is line 2" & Chr(10) & "This is line 3" /> 

OR

<cfset NL=Chr(10) /> <cfset someStr="This is line 1#NL#This is line 2#NL#This is line 3" /> 

Is there anything more like the Java/C++ way? Something more like this I mean:

<cfset someStr="This is line 1\nThis is line 2\nThis is line 3" /> 
like image 939
Kip Avatar asked Jun 12 '09 15:06

Kip


2 Answers

Your way is correct. There is no support for \n or \r in CF. From the Live Docs

  • Chr(10) returns a linefeed character
  • Chr(13) returns a carriage return character
  • The two-character string Chr(13) & Chr(10) returns a Windows newline
like image 198
Nick Van Brunt Avatar answered Oct 22 '22 04:10

Nick Van Brunt


If you are into platform-independent development, you can do:

<cfset NL = CreateObject("java", "java.lang.System").getProperty("line.separator")> 

For example, in your application.cfm/cfc or somewhere else high-level and use that.

like image 28
Tomalak Avatar answered Oct 22 '22 02:10

Tomalak