Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to replace new line to empty space on coldfusion

Tags:

coldfusion

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

Above code produce the this kind of output

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?

my task is replace the new line character but i can't. if any way to do that please let me know?

like image 395
cfprabhu Avatar asked Feb 13 '23 14:02

cfprabhu


1 Answers

I can understand your issue but we cannot produce a newline character by cfset. And #chr(13) & chr(10)# is not valid. it should be either chr(13) or chr(10). You can do two replaces one by one. And ReReplace function is used to replace string based on a RegEx. You can use replaceNoCase here. Here is my sample code.

  <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>
like image 85
Marikkani Chelladurai Avatar answered Feb 15 '23 04:02

Marikkani Chelladurai