Formatting Techniques
Once you have query data in the form of a result set, you might want to massage it a bit before outputting it to the browser or to a file. ColdFusion provides several built-in functions for formatting a variety of datatypes. This section covers some of the more popular functions for formatting strings, HTML code, numbers, currency, dates, times, and Boolean values. For more information on all the functions covered in this section, see Appendix B.
Formatting Plain-Text Strings
ColdFusion provides functions for
formatting text strings: ParagraphFormat( ),
Wrap( ), Ucase( ),
Lcase( ), JSStringFormat( ),
and XMLFormat( ). Each function is covered in the
sections that follow.
Using ParagraphFormat
ParagraphFormat(
)takes a string and formats it so that single newline
characters are replaced with a space, and double newline characters
are replaced with HTML <p> tags. This
function is most often used to display data that has been entered
into a Textarea HTML form field. The following
example shows how the ParagraphFormat( ) function
handles single and double newline characters:
<cfset MyText="This is my block of text. It has both single newline characters in it like this paragraph, and double newline characters like in the next paragraph. This is the paragraph with the double newline characters."> <form> <cfoutput> <textarea cols="50" rows="10" name="TheText" wrap="Virtual"> #ParagraphFormat(MyText)# </textarea> </cfoutput> </form>
Wrapping text
As of ColdFusion ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access