ToString

Description

Converts a value to a string.

Return value

A string.

Category

Conversion functions, Other functions, String functions

Syntax

ToString(any_value[, encoding]) 

See also

History

New in ColdFusion MX: ColdFusion supports the Java UCS-2 representation of Unicode character values 0-65535. (ColdFusion 5 and earlier releases supported ASCII values 1-255.)

New in ColdFusion MX: the encoding attribute is new.

Parameters

Parameter Description
any_value
Value to convert to a string
encoding
Defines how characters are represented in a string:
  • US-ASCII
  • ISO-8859-1
  • UTF-8
  • UTF-16
Default: the encoding option of the page on which the function is called. See cfcontent.
The Java platform determines the available options.

Usage

This function can convert simple values and binary values that do not contain Byte zero. If this function cannot convert a value, it throws an exception. This function can convert an XML document object to a string representation.

Note:   You can use this function to reverse Base64 encoding of a string. Convert the Base64 encoded object to a binary object, then use this function to convert the binary object to a string.

Example

<h3>ToString Example</h3>
<!---- Initialize data. ------>
<cfset charData = "">
<!----- Create string of ASCII characters (32-255) and concatenate them. ---->
<cfloop index = "data" from = "32" to = "255">
  <cfset ch = chr(data)>
  <cfset charData = charData & ch>
</cfloop>
<p>The following string is the concatenation of characters (32 to 255) 
from the ASCII table.<br>
<cfoutput>#charData#</cfoutput></p>

<!------ Create a Base64 representation of this string. ---->
<cfset data64 = toBase64(#charData#)>
<p>
The following string is the Base64 representation of the string.<br>
<cfoutput>#data64#</cfoutput></p>
<!---- Create a binary representation of Base64 data. --->
<cfset dataBinary = toBinary(data64)>

<!---- Create the string repesentation of the binary data. ----->
<cfset dataString = toString(dataBinary)>
<p>The following is the string representation of the binary data.<br>
<cfoutput>#dataString#</cfoutput></p>

Comments