Question

I cannot convince why I cannot break line in notepad with coldfusion.

Here is my coding

<cfscript>
    msg = "ppshein<CR>Coldfusion Developer<CR>Currently working in Singapore";
    currentPath = getCurrentTemplatePath();
    currentDirectory = getDirectoryFromPath(currentPath);
    chgMsg = ReReplace(msg, "<CR>", "<CR>\r\n", "ALL");
    FileWrite("#currentDirectory#\myfile.txt", "#chgMsg#");
    return "successfully generated";
</cfscript>

what I run above coding and open myfile.txt, it happen so

ppshein<CR>Coldfusion Developer<CR>Currently working in Singapore

What I want is

ppshein<CR>
Coldfusion Developer<CR>
Currently working in Singapore

Any comments will be appreciated.

Was it helpful?

Solution

Don't think you need ReReplace here, plus your replacement string is incorrect -- CF does not recognize this format. Try this one:

chgMsg = Replace(msg, "<CR>", chr(13)&chr(10), "ALL");

UPD. Let me try to optimize whole block of code a bit...

<cfscript>
    msg = "ppshein<CR>Coldfusion Developer<CR>Currently working in Singapore";
    chgMsg = Replace(msg, "<CR>", chr(13)&chr(10), "ALL");
    FileWrite(ExpandPath("./myfile.txt"), chgMsg);
    return "successfully generated";
</cfscript>

A bit more clean and easy to read.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top