2010-11-22 48 views
0

我無法說服爲什麼我不能用coldfusion在記事本中斷行。在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 

任何評論都不勝感激。

回答

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> 

有點乾淨,容易閱讀。

+0

天哪..對。我給了錯誤的代碼。實際代碼如下。 chgMsg =替換(msg,「」,「」&chr(13),「ALL」); 我忘了在chr(13)之後放置chr(10)。謝謝你的時間。 – ppshein 2010-11-22 12:07:55