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" />
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With