Converting Text From UTF-8 to ISO-8859-1

Recently, I had a need to convert text from UTF08 to iso-8859-1. Actually, the need was to come up with a more efficient way of doing so. I'll spare you the why, when and where and get right to the how.

After digging into the java.nio.charset.Charset, this is what I came up with the following function. (commented for your viewing pleasure)


<cfscript>
function convertutfToIso(str)
{
//var a struct to store all of our stuff in

var local = {};

//Create an object of java.nio.charset.Charset

local.charSetObj = createobject("java", "java.nio.charset.Charset");

//What the text is currently

local.convertFrom = local.charsetObj.forName('iso-8859-1');

//What to convert the text to

local.convertTo = local.charsetObj.forName('utf-8');

//return the converted text

return local.convertTo.decode(local.convertFrom.encode(str)).ToString();
}
</cfscript>



Now anytime that I need to ensure some provided text is iso-8859-1, I can simply convert it like so:



<cfset isoText = convertUtfToIso(utfText) />



This worked well on some rather large chunks of text with many characters that needed to be converted.

Of course you can change the "to" and "from" to suit your needs but that should get you started.

Enjoy.

Recently Added Photos

Angie and I stopped on the side of the road in the Outer Banks and followed a path to an empty beach We found tons of nice shells and there was no one around We stayed until the crabs came out and Angie decided that they were plotting against us Angie and I stopped on the side of the road in the Outer Banks and followed a path to an empty beach We found tons of nice shells and there was no one around We stayed until the crabs came out and Angie decided that they were plotting against us Angie and I stopped on the side of the road in the Outer Banks and followed a path to an empty beach We found tons of nice shells and there was no one around We stayed until the crabs came out and Angie decided that they were plotting against us Angie and I stopped on the side of the road in the Outer Banks and followed a path to an empty beach We found tons of nice shells and there was no one around We stayed until the crabs came out and Angie decided that they were plotting against us Angie and I stopped on the side of the road in the Outer Banks and followed a path to an empty beach We found tons of nice shells and there was no one around We stayed until the crabs came out and Angie decided that they were plotting against us Angie and I stopped on the side of the road in the Outer Banks and followed a path to an empty beach We found tons of nice shells and there was no one around We stayed until the crabs came out and Angie decided that they were plotting against us Angie and I stopped on the side of the road in the Outer Banks and followed a path to an empty beach We found tons of nice shells and there was no one around We stayed until the crabs came out and Angie decided that they were plotting against us Angie and I stopped on the side of the road in the Outer Banks and followed a path to an empty beach We found tons of nice shells and there was no one around We stayed until the crabs came out and Angie decided that they were plotting against us Angie and I stopped on the side of the road in the Outer Banks and followed a path to an empty beach We found tons of nice shells and there was no one around We stayed until the crabs came out and Angie decided that they were plotting against us Angie and I stopped on the side of the road in the Outer Banks and followed a path to an empty beach We found tons of nice shells and there was no one around We stayed until the crabs came out and Angie decided that they were plotting against us Angie and I stopped on the side of the road in the Outer Banks and followed a path to an empty beach We found tons of nice shells and there was no one around We stayed until the crabs came out and Angie decided that they were plotting against us Angie and I stopped on the side of the road in the Outer Banks and followed a path to an empty beach We found tons of nice shells and there was no one around We stayed until the crabs came out and Angie decided that they were plotting against us Angie and I stopped on the side of the road in the Outer Banks and followed a path to an empty beach We found tons of nice shells and there was no one around We stayed until the crabs came out and Angie decided that they were plotting against us Angie and I stopped on the side of the road in the Outer Banks and followed a path to an empty beach We found tons of nice shells and there was no one around We stayed until the crabs came out and Angie decided that they were plotting against us Angie and I stopped on the side of the road in the Outer Banks and followed a path to an empty beach We found tons of nice shells and there was no one around We stayed until the crabs came out and Angie decided that they were plotting against us Angie and I were on our way to Jockeys Ridge when we saw the Wright Brothers National Memorial We thought Hey something else to climb So we stopped and hiked to the top to check it out Angie and I were on our way to Jockeys Ridge when we saw the Wright Brothers National Memorial We thought Hey something else to climb So we stopped and hiked to the top to check it out Angie and I were on our way to Jockeys Ridge when we saw the Wright Brothers National Memorial We thought Hey something else to climb So we stopped and hiked to the top to check it out
Login
Password Reset