<html>
<head>
<link href="mmres://user_interface_reference.css" rel="stylesheet" type="text/css">
<title>CHARSETENCODE</title>
</head>
<body bgcolor="#FFFFFF" text="#000000">
   <div id="Description">
   <table cellpadding="0" cellspacing="0" border="0" width="100%" class="main">
      <tr> 
         <td valign="top" class="name">CHARSETENCODE</td>
         <td valign="top" nowrap class="compatibility">&nbsp;</td>
      </tr>
      <tr>
         <td colspan="2" class="divider"><img src="dwres:18084" width="100%" height="1"></td>
      </tr>


    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">Description</span>
<p>
Uses the specified encoding to convert binary data to a string.
</p>
    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">Returns</span>
<p>
A string representation of the binary object.
</p>
    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">Category</span>
<p>
Conversion functions, String functions
</p>
    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">Function syntax</span><pre>CharsetEncode(binaryobject, encoding)
</pre>    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">See also</span>
<p>
BinaryDecode, BinaryEncode, CharsetDecode; "Determining the page encoding of server output" in Chapter&#160;17, "Developing Globalized Applications," in ColdFusion MX Developer's Guide
</p>
    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">History</span>
<p>
ColdFusion&#160;MX&#160;7: Added this function.
</p>
    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">Parameters</span>
<p>

</p>
    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">Usage</span>
<p>
Macromedia recommends that you use this function, and not the ToString function, to convert binary data to strings in all new applications.
</p>
    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">Example</span>
<p>
The following example uses the CharsetDecode function to convert a string from a form to a binary object, and uses the CharsetEncode function to convert it back to the original value. You can change the character encoding that ColdFusion uses for the conversion. Notice that if you select the Asian language encodings, characters that are not in the specified character set do get successfully converted.
</p>
<pre>&lt;h3&gt;Character Encoding Conversion Example&lt;/h3&gt;
&lt;!--- Do the following if the form has been submitted. ---&gt;
&lt;cfif IsDefined(&quot;Form.myString&quot;)&gt;

   &lt;!--- Do the conversions. ---&gt;
   &lt;cfscript&gt;
      chardecode=CharsetDecode(Form.myString, Form.charEncoding);
      charencode=CharsetEncode(chardecode, Form.charEncoding);
   &lt;/cfscript&gt;

   &lt;!--- Display the input values and results. ---&gt;
   &lt;cfoutput&gt;
      &lt;h3&gt;Parameter Settings&lt;/h3&gt;
      &lt;p&gt;&lt;b&gt;The string:&lt;/b&gt;&lt;br&gt;
          #Form.myString#&lt;/p&gt;
      &lt;p&gt;&lt;b&gt;The character encoding:&lt;/b&gt; #Form.charEncoding#&lt;/p&gt;
      
      &lt;h3&gt;Results of the operations:&lt;/h3&gt;
      &lt;p&gt;&lt;b&gt;Dump of the string converted to a binary object by CharsetDecode: 
         &lt;/b&gt;&lt;br&gt;
         &lt;cfdump var=&quot;#chardecode#&quot;&gt;&lt;/p&gt;
      &lt;p&gt;&lt;b&gt;The binary object converted back to a string by CharsetEncode: 
         &lt;/b&gt;&lt;br&gt;
      #charencode#&lt;/p&gt;
   &lt;/cfoutput&gt;
&lt;/cfif&gt;

&lt;!--- The input form. ---&gt;
&lt;form action=&quot;#CGI.SCRIPT_NAME#&quot; method=&quot;post&quot;&gt;
   &lt;b&gt;Select the character encoding&lt;/b&gt;&lt;br&gt;
   &lt;!--- This is a subset, additional encodings are available. ---&gt;
   &lt;select size=&quot;1&quot; name=&quot;charEncoding&quot; &gt;
      &lt;option selected&gt;UTF-8&lt;/option&gt;
      &lt;option&gt;ASCII&lt;/option&gt;
      &lt;option&gt;ISO8859_1&lt;/option&gt;
      &lt;option&gt;CP1252&lt;/option&gt;
      &lt;option&gt;SJIS&lt;/option&gt;
      &lt;option&gt;MS932&lt;/option&gt;
      &lt;option&gt;EUC_CN&lt;/option&gt;
      &lt;option&gt;Big5&lt;/option&gt;
   &lt;/select&gt;&lt;br&gt;
   &lt;br&gt;
   &lt;b&gt;Enter a string&lt;/b&gt;&lt;br&gt;
   &lt;textArea name = &quot;myString&quot; cols = &quot;40&quot; rows = &quot;5&quot; WRAP = &quot;VIRTUAL&quot;&gt;
The following four characters are not in all character encodings: 
   &lt;/textArea&gt;&lt;br&gt;
   &lt;br&gt;
   &lt;input type = &quot;Submit&quot; value = &quot;convert my data&quot;&gt;
&lt;/form&gt;
</pre>
         </td>
      </tr>
   </table>
   </div>
<div id="BINARYOBJECT">
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>  
<td valign="top" class="name">BINARYOBJECT</td>
  <td valign="top" nowrap class="compatibility">&nbsp;</td>
  </tr>
  <tr>
  <td colspan="2" class="divider"><img src="dwres:18084" width="100%" height="1"></td>
  </tr>


<p>A variable containing binary data to decode into text.</p>

  </td>
  </tr>
  </table>
</div>
<div id="ENCODING">
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>  
<td valign="top" class="name">ENCODING</td>
  <td valign="top" nowrap class="compatibility">&nbsp;</td>
  </tr>
  <tr>
  <td colspan="2" class="divider"><img src="dwres:18084" width="100%" height="1"></td>
  </tr>


<p>The character encoding that was used to encode the string into binary format. It must be a character encoding name recognized by the Java runtime. The following list includes commonly used values:</p><ul>

<li>utf-8</li>

<li>iso-8859-1 </li>

<li>windows-1252</li>

<li>us-ascii</li>

<li>shift_jis</li>

<li>iso-2022-jp </li>

<li>euc-jp</li>

<li>euc-kr</li>

<li>big5</li>

<li>euc-cn</li>

<li>utf-16</li>
</ul>

<p>For a complete list of character encoding names supported by Sun Java runtimes, see http://java.sun.com/j2se/1.3/docs/guide/intl/encoding.doc.html</a> and http://java.sun.com/j2se/1.4/docs/guide/intl/encoding.doc.html</a>.</p>

  </td>
  </tr>
  </table>
</div>

  </body>
</html>
