ToString

Description

Attempts to convert a value of any type, including a binary value, into a string.

Category

Conversion functions

Syntax

ToString(any_value) 

Parameters

Parameter
Description
any_value
The value to convert to a string

Usage

If ToString cannot convert the value into a string, it throws an exception. Simple values can be converted into a string. Binary values that do not contain byte zero can be converted.


Note

You can use the ToString function to reverse the Base64 encoding of a string. First, convert the Base64 encoded object into a binary object, and then convert the binary object into a string using ToString.


Example

<!--- This example shows the use of ToBase64, ToBinary and ToString --->
<html>
<head>
<title>
ToString Example
</title>
</head>

<body bgcolor = silver>
<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 
original 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>
</body>
</html>