我需要将字符串写入文本文件,但在此之前我需要确保该字符串不包含任何换行符,回车符或制表符。
我已尝试过此代码进行测试。
<cfset str = "a#chr(10)#bc#chr(13)#def#chr(9)#fg">
<cfset cleanedStr = reReplace(str,"#chr(13)##chr(10)#","","ALL")>
<cfset cleanedStr = reReplace(str,"#chr(10)#","","ALL")>
<cfset cleanedStr = reReplace(str,"#chr(13)#","","ALL")>
<cfset cleanedStr = reReplace(str,"#chr(9)#","","ALL")>
<cffile action="write" file="D:/projects/test.txt" output="#cleanedStr#">
但是当我在Eclipse中打开文件时,它仍然显示换行符和cariage返回字符。
那么删除这些字符的正确方法是什么?
答案 0 :(得分:1)
尝试:
<cfset str = "a#chr(10)#bc#chr(13)#def#chr(9)#fg">
<cfset cleanedStr = reReplace(str,"\s","","ALL")>
<cffile action="write" file="D:/project/test.txt" output="#cleanedStr#">