<cfoutput>
<cfset str ="hai how are you? i am fine
what about you?" >
<cfdump var="#str#" /><br>
<cfset str = #replace(str,"#chr(13)&chr(10)#"," ","all")#>
<cfdump var="#str#" /><br>
<cfset str = #reReplace(str, "#chr(13)&chr(10)#"," ")#>
<cfdump var="#str#" />
</cfoutput>
上面的代码产生了这种输出
hai how are you? i am fine what about you?
hai how are you? i am fine what about you?
hai how are you? i am fine what about you?
我的任务是替换新行字符,但我不能。如果有任何办法,请告诉我?
答案 0 :(得分:7)
我可以理解你的问题,但我们不能通过cfset生成换行符。 #chr(13)&amp; chr(10)#无效。它应该是chr(13)或chr(10)。你可以逐个替换两个。并且 ReReplace 函数用于基于RegEx替换字符串。你可以在这里使用replaceNoCase。这是我的示例代码。
<cfif isDefined("form.submit")>
<cfset str =form.TestField>
<cfoutput>
#findNoCase(Chr(13), str)# <!--- It is available --->
<cfset str = replaceNoCase(str, chr(13), ' ','All')>
<cfset str = replaceNoCase(str, chr(10), ' ','All')>
<cfdump var="#str#"><!--- string after replacement --->
</cfoutput>
</cfif>
<form name="test" method="post">
<textarea name="TestField"></textarea>
<input type="submit"name="submit" value="submit">
</form>