2010-11-22 27 views
0

なぜ私はcoldfusionでメモ帳の行を壊すことができません。ここでcoldfusionでメモ帳に改行します

は、私はすべてのコメントは、私は、コーディングやオープンmyfile.txtの上で実行するもの、それは私が欲しいので

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

起こること

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

ある

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

をしますコーディングです感謝する。

答えて

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

Gosh .. !!右。私は間違ったコードを与えました。実際のコードは次のとおりです。 chgMsg = Replace(msg、 ""、 ""&chr(13)、 "ALL"); 私はchr(13)の後にchr(10)を置くのを忘れてしまいました。御時間ありがとうございます。 – ppshein