Copy link to clipboard
Copied
Hi Friends,
I am knew to CF - 11..I am trying to insert line break after 64 letters and dont know how to change below line. Kindly help. and also if possible please explain below line.
<cfset outstr &= Mid(instr,p,64) & #Chr(13)#>
Thanks
My code as follows.
<cfset instr = rereplace(arguments.value,"#chr(10)#","","all")>
<cfset instr = rereplace(instr,"#chr(13)#","","all")>
<cfset instr =trim(instr)>
<cfloop from="1" to="#len(instr)#" index="p" step="64">
<cfset outstr &= Mid(instr,p,64) & #Chr(13)#>
</cfloop>
currently I an getting a long string with a space after 64 letters as output.
You could probably eliminate the cfloop altogether, since you're using the RegEx replace.
So, walk me through your code.
You're replacing all chr(10) and chr(13) with nothing, then you trim the string. Then you loop and insert just a chr(13) every 64th position.
AFAIK, if you're using the Windows CF Server, both chr(13) AND chr(10) are the line break/carriage return codes.
Also, don't use hashmarks (#) for variables, unless the variable is either being output to the screen, or is inside the string
...Copy link to clipboard
Copied
You could probably eliminate the cfloop altogether, since you're using the RegEx replace.
So, walk me through your code.
You're replacing all chr(10) and chr(13) with nothing, then you trim the string. Then you loop and insert just a chr(13) every 64th position.
AFAIK, if you're using the Windows CF Server, both chr(13) AND chr(10) are the line break/carriage return codes.
Also, don't use hashmarks (#) for variables, unless the variable is either being output to the screen, or is inside the string delimiters. (Doing <cfset outstr &= Mid(instr,p,64) & #chr(13)#> is not advised. Remove the #'s around the chr(13).)
Hmm.. I haven't tested this, but try the following:
<cfset instr = trim(rereplace(arguments.value,"#chr(13)&chr(10)#|#chr(13)#|#chr(10)#","","all")) />
<!--- One way of removing all line breaks, and trimming; there are others --->
<cfset instr = rereplace(instr,"(.){64}","\1#chr(13) & chr(10)#","all") />
<!--- \1 is the backreference; equivalent to JavaScript RegEx $1 --->
Let me know if that works.
HTH,
^_^
UPDATE: I had a chance to test it, and with two minor corrections, it works.
<cfset instr = rereplace(instr,"(.{64})","\1#chr(13) & chr(10)#<br/>","all") /> The <br /> will display line breaks in the browser, but without it you can see the line breaks if you "View Source" the page.
Copy link to clipboard
Copied
Thank a lot WolfShade .Even though its working fine in browser. while downloading the certificate the format is not aligned. I am getting single line instead of (64 letters in a line) and a space after each 64 letters
Copy link to clipboard
Copied
How are you using the resulting string? The <br />, if you included it, may be messing things up.
Conversely, if you are just outputting the text to a browser, then check the "View Source", because a line break in the code will appear as a space in the browser, in which case the <br /> would be necessary to force the sections onto their own line in the browser display.
HTH,
^_^
Copy link to clipboard
Copied
Thank you so much WolfShade..The issue resolved now..I missed chr(10) in a place which caused the issue.Thanks a lot for you timely help
Copy link to clipboard
Copied
Glad I could help. BTW, where was is chr(10) that you missed?
If you could, please, mark my answer as correct, in case anyone else has the same question.
V/r,
^_^