我需要将字符串写入文本文件,但在此之前,我需要确保该字符串不包含换行符、回车符或制表符。以下是我用于测试的代码:
<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中打开文件时,它仍然显示了换行和回车符。
那么正确的方法是什么来删除这些字符呢?
\s
来匹配换行、制表符、回车和空格。 - Braja#chr(10)#bc#chr(13)#deffg
,因为你一直在基于原始字符串替换同一个变量为新的字符串。 - Twillen