我无法说服为什么我不能用冷敷在记事本中断线。
这是我的编码
<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
任何意见将不胜感激。
答案 0 :(得分: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>
更干净,更容易阅读。