与ColdFusion的记事本换行符
-
27-09-2019 - |
题
我无法说服为什么我可以在记事本中使用ColdFusion不会破裂线。
下面是我的编码
<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
任何意见将受到赞赏。
解决方案
不认为你需要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>
一个位更干净和容易阅读。
不隶属于 StackOverflow