gpt4 book ai didi

coldfusion - 如何在coldfusion上将新行替换为空白

转载 作者:行者123 更新时间:2023-12-04 23:50:09 24 4
gpt4 key购买 nike

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

我的任务是替换新行字符,但我不能。如果有什么办法可以让我知道吗?

最佳答案

我可以理解您的问题,但我们无法通过 cfset 生成换行符。和 #chr(13) & chr(10)# 无效。它应该是 chr(13) 或 chr(10)。您可以一一进行两次替换。和 更换 函数用于基于正则表达式替换字符串。您可以在此处使用 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>

关于coldfusion - 如何在coldfusion上将新行替换为空白,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24527320/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com