Skip to main content
Inspiring
November 3, 2010
Answered

Replace New Line Expression

  • November 3, 2010
  • 2 replies
  • 5838 views

Hi,

I have a java object that returns a string object from a method in this format:

This is a test \n And it continues \n And continues \n etc...

When I get this string object in ColdFusion, somehow it doesnt recognize \n. I would like to replace \n with <br> html tag. Does anyone know know how to solve to issue?

Btw, I tried using ReReplace, and its not working for me.

Thanks,

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

    cfSearching,

    I tried using something along this line:

    ReReplace(description, "chr(10)", "<br>")

    But this does not seems to work. I have tried this as well:

    ReReplace(description, "\n", "<br>")

    If I dump the variable, CF shows everything on one line without "\n" in the expression.


    First, did you determine if it really is chr(10)? No point trying to replace something unless you know what that "something" is

    I tried using something along this line:

    ReReplace(description, "chr(10)", "<br>")

    If it is really chr(10), get rid of the double quotes around it. Otherwise CF will be searching for the literal characters "chr(10)", not a line feed.

    2 replies

    Participating Frequently
    November 3, 2010

    #replace(stringReturnVar, "\n", "<br />", "all")#

    You don't need reReplace() in this case, just simple string replace

    Inspiring
    November 3, 2010

    You don't need reReplace() in this case, just simple string

    replace

    Only if it is the literal characters "\n". Usually "\n" is equivalent to chr(10) in java.

    splitzerAuthor
    Inspiring
    November 4, 2010

    cfSearching,

    I tried using something along this line:

    ReReplace(description, "chr(10)", "<br>")

    But this does not seems to work. I have tried this as well:

    ReReplace(description, "\n", "<br>")

    If I dump the variable, CF shows everything on one line without "\n" in the expression.

    Inspiring
    November 3, 2010

    Does anyone know know how to solve to issue?

    You need to determine how the character(s) are perceived in CF. IIRC, "\n" is usually chr(10). But verify that with string functions. Just find the offending character(s) and check the ascii value(s).

    splitzerAuthor
    Inspiring
    November 3, 2010

    How do I find the "offending character(s)"? I assume using asc() function and then replacing it with replace() function?

    I also, I should  have noted:

    When I write output to the browser, I the result as (without escape characters):

    This is a test And it continues And continues etc...