How to replace a new line with empty space in the cold

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

The above code produces 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 replaces the new character of the string, but I cannot. if any way to do this please let me know?

+4
source share
1 answer

I can understand your problem, but we cannot create a newline character cfset. Both #chr (13) and chr (10) # are invalid. it should be either chr (13) or chr (10). You can make two replacements one by one. And the ReReplace function is used to replace a RegEx-based string. Here you can use replaceNoCase. 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>
+7
source

Source: https://habr.com/ru/post/1546815/


All Articles