使用 Coldfusion 在记事本中换行

发布于 2024-10-04 02:31:21 字数 757 浏览 4 评论 0原文

我无法说服为什么我不能用 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

任何评论将不胜感激。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

亢潮 2024-10-11 02:31:21

不要认为这里需要 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>

更干净且易于阅读。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文