String encoding conversion

20 July 2007 10:42 (EST)
You can use following code to convert string encoding using Java library:

<cfset oCharset = createObject("java","java.nio.charset.Charset") />
<cfset fromCharSet = oCharset.forName('utf-8') />
<cfset toCharSet = oCharset.forName('iso-8859-1') />
<cfset b = toCharSet.decode(fromCharSet.encode(q)).ToString() />

Every implementation of the Java platform is required to support the following standard charsets. Consult Java release documentation for your implementation to see if any other charsets are supported. Following charsets are supported with Java 2 Platform SE v1.4.2:

US-ASCII = Seven-bit ASCII, a.k.a. ISO646-US, a.k.a. the Basic Latin block of the Unicode character set
ISO-8859-1 = ISO Latin Alphabet No. 1, a.k.a. ISO-LATIN-1
UTF-8 = Eight-bit UCS Transformation Format
UTF-16BE = Sixteen-bit UCS Transformation Format, big-endian byte order
UTF-16LE = Sixteen-bit UCS Transformation Format, little-endian byte order
UTF-16 = Sixteen-bit UCS Transformation Format, byte order

Discussion (1 comment)

PaulH PaulH: 20 July 2007 14:14 (EST)

java supports rather a lot more encodings than those & i've yet to see an install that didn't support the "optional" charsets. see:
http://www.sustainablegis.com/projects/i18n/charsetTB.cfm
your example of converting utf-8 to latin-1 doesn't make a whole lot of sense as the majority of "chars" in unicode *can't* be converted to latin-1 at least that make any sense. the other way round works better.

Dmitry Yakhnov Dmitry Yakhnov: 20 July 2007 17:07 (EST)

That example fix the issue with Google Search API request through cfinvoke I have blogged about yesterday.

Dharmender Yadav Dharmender Yadav: 25 June 19:30 (EST)

Hi,
I am creating a CSV file and then saving it as xls.
On the web, content is rendering properly but when I import it in Excel 2007 it is displaying special characters differently. The DB is UTF-8.
Could you please help in fixing this issue? Or give any inputs?
Cheers,
Dharmender

Add your comment
*
*
*
*
*

Captcha Code Please enter the number on the left.
Sorry for asking you to do so.
Reload image