Skip to main content
Inspiring
April 8, 2008
Question

Looping over a list with a 'NP form feed, new page' character [ascii(12)]

  • April 8, 2008
  • 3 replies
  • 353 views
I have a text file that I am trying to loop over using the "NP form
feed, new page" character. The ultimate goal is to output this text
file as a PDF with <cfdocument...> replacing that ASCII(12) character
with <cfdocumentitem type="pagebreak"/> tags.

If I output the text file character by character I count 6 ascii(12)
characters.
<pre>
<cfscript>
for (i=1; i <= len(report); i++)
{
char = mid(report,i,1);

if (asc(char) eq 12)
writeOutput('<strong>[' & asc(char) & ']</strong>' & char);
else
writeOutput('[' & asc(char) & ']' & char);
}
</cfscript>
</pre>

If I loop over the text file delimiting on the asc(12) character, I get
41 items rather then the expected 7.
<cfoutput>
<pre>
<cfloop list="#report#" delimiters="#asc(12)#" index="page">
#page#
<hr/>
</cfloop>
</pre>
</cfoutput>

Any idea why my code is not producing consistent results?
This topic has been closed for replies.

3 replies

Inspiring
April 8, 2008
Azadi wrote:
> delimiter="#chr(12)#" maybe?

DOH!!! Yes, asc() tells one the number and chr() matches the character
of that number!

Thank you Azadi, that was not getting through my sleep deprived brain
this morning.
Inspiring
April 8, 2008
...
asc(chr(12)) = 12
asc(12) = 49

Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com/
Inspiring
April 8, 2008
delimiter="#chr(12)#" maybe?
asc(char)=12 != char=12...

Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com/