I would like to insert a line break into the first space between words in a string variable. Here is my code so far:
<cfset myPosition = find(" ", #myVar#)>
<cfset lineBreak = Chr(13)&Chr(10)>
<cfset myVar = insert(#lineBreak#, #myVar#, #myPosition#)>
What am I doing wrong?
I don’t think that you are doing anything wrong. Your code seems to work. When you output your variable, try wrapping it in
<pre></pre>tags for testing purposes. If you want the linebreak to show up on a html page you have to replace the space with<br />.This works for me and shows the carriagereturn / linefeed:
BTW: there is no need to enclose your variables in #’s unless you want to output the variable or to have it evaluated between quotation marks.