Skip to main content
lovewebdev
Inspiring
January 11, 2010
Answered

Create an ASCII new line inside a variable?

  • January 11, 2010
  • 3 replies
  • 1645 views

I have

<cfset stringineed = varibale1 & "\n" & variable2 & "\n" & variable3 & "\n" & variable3>

I need "\n" to produce an ASCII new line but it doesn't. it just sends the actual \n characters.

This is not to be dispayed in an HTML page which of coruse I would use <br />

But instead it's to be sent to a coldfusion function which is why I need an ASCII new line.

This topic has been closed for replies.
Correct answer -__cfSearching__-

Use the CHR() function. You can use CHR(10) or possibly CHR(10) & CHR(13) (depending on your definition of new line).

3 replies

January 12, 2010

Dont you also have to put the chr(10)chr(13) in pound signs for them to actually create the ascii character?

#chr(10)##chr(13)#

Chuck

Inspiring
January 12, 2010

Dont you also have to put the chr(10)chr(13) in pound signs

for them to actually create the ascii character?

Not in the OP's case. Since the variables and functions are not enclosed in quotes, CF will recognize them as something that must be evaluated (not just plain text).

cfset x = variable1 & CHR(10) & variable2

But the real answer is "it depends". If that function were used inside quotes, you typically do need # signs. Otherwise CF will think chr(10) is just a plain string:

--- does not work ---

cfset x = "appleCHR(10)orange"

--- works ---

cfset x = "apple#CHR(10)#orange"

lovewebdev
Inspiring
January 11, 2010

Yes <pre> and textarea show that its creating a new line, Thanks!

-__cfSearching__-Correct answer
Inspiring
January 11, 2010

Use the CHR() function. You can use CHR(10) or possibly CHR(10) & CHR(13) (depending on your definition of new line).

lovewebdev
Inspiring
January 11, 2010

<cfset stringineed = varibale1 & chr(10) & variable2 & chr(10) & variable3 & chr(10) & variable3>

That doesn't seem to be creating a new line, it creates a space in between the variables.

the value of the variable stringineed something like this

value1

value2

value3

Inspiring
January 11, 2010

What program are viewing it with? Your basic web page does not understand chr(10) as a line break.