• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

LEGEND ,
Apr 08, 2008 Apr 08, 2008

Copy link to clipboard

Copied

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?
TOPICS
Advanced techniques

Views

287

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 08, 2008 Apr 08, 2008

Copy link to clipboard

Copied

delimiter="#chr(12)#" maybe?
asc(char)=12 != char=12...

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 08, 2008 Apr 08, 2008

Copy link to clipboard

Copied

...
asc(chr(12)) = 12
asc(12) = 49

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 08, 2008 Apr 08, 2008

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation