Coldfusion: insert a new line into a line

I would like to insert a line break in the first space between words in a string variable. Here is my code:

    <cfset myPosition = find(" ", #myVar#)>
    <cfset lineBreak = Chr(13)&Chr(10)>
    <cfset myVar = insert(#lineBreak#, #myVar#, #myPosition#)>

What am I doing wrong?

+3
source share
1 answer

I don’t think you are doing something wrong. Your code seems to work. When you output your variable, try wrapping it in tags <pre></pre>for testing purposes. If you want the linebreak to appear on the html page, you need to replace the space with <br />.

This works for me and shows carriagereturn / linefeed:

<cfset myVar="The quick brown fox">
<cfset myPosition = find(" ", myVar)>
<cfset lineBreak = Chr(13) & Chr(10)>
<cfset myVar = insert(lineBreak, myVar, myPosition)>
<cfoutput>
   <pre>#myVar#</pre>
</cfoutput>

BTW: #, .

+8

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


All Articles