4

我需要将字符串写入文本文件,但在此之前我需要确保字符串不包含任何换行符、回车符或制表符。

我已经尝试过此代码进行测试。

<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 中打开文件时,它仍然显示换行符和回车符。

文本编辑器图像

那么删除这些字符的正确方法是什么?

4

1 回答 1

3

尝试:

<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#">
于 2014-07-31T15:33:39.550 回答