0

我无法说服为什么我不能在记事本中用冷熔断线。

这是我的编码

<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>

我在编码上面运行并打开myfile.txt,它发生了

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

我想要的是

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

任何意见将不胜感激。

4

1 回答 1

2

不要认为你需要 ReReplace 这里,加上你的替换字符串不正确 - CF 不识别这种格式。试试这个:

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

UPD。让我尝试优化整个代码块......

<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>

更干净,更易于阅读。

于 2010-11-22T11:42:10.370 回答