Convert a UTF-8 string to ISO-8859-1 string

Hello. As you can see from my other post, I am working on internationalization. I could not find an appropriate entry in the forum already.

I want to convert form data (submitted from an HTML UTF-8 charset page) from the UTF-8 format to ISO-8859-1 format. How do I do that?

I.e.

String utfFormat="視聴者";

String isoFormat="";

// Do magic here

System.out.println(isoFormat); // out: "しての" (or whatever it is)

Can you help?

Dailysun

null

[549 byte] By [dailysuna] at [2007-10-2 21:15:45]
# 1

> "しての" (or whatever it is

I think these can be done on browser side if you set META charset to ISO-8859-1

or set nothing.

for your reference:

http://homepage1.nifty.com/algafield/core1.html

http://homepage1.nifty.com/algafield/UTF8CeToJavaString.java.txt

hiwaa at 2007-7-14 0:23:40 > top of Java-index,Java Essentials,Java Programming...
# 2
new String( "帇挳幰".getBytes("utf-8"), "latin1" ); // from utf-8 to latin1(ISO-8859-1) // but you cannot view the chinese in latin1. I use this or similar technique to deal with wrong encoding from Java
evilknighthka at 2007-7-14 0:23:40 > top of Java-index,Java Essentials,Java Programming...
# 3

As I said in the other thread (did you read that, BTW?), you shouldn't have to bother with actual character-set conversions.You just tell the InputStream what the Charset is when you read it in, and the OutputStream what Charset to use when you write it out.

What you're doing is escaping characters by replacing them with numeric entity references--the opposite of what you asked in the other thread. The process is just as simple: cast the char to an int, convert that to a string with String.valueOf(int), and add the "&#" and ";". You can use a regex-based approach like I did over there, but going in this direction, it will be just as easy without them.

Hiwa, check out that other thread; I think you'll find it amusing (in light of that second link you posted).

uncle_alicea at 2007-7-14 0:23:40 > top of Java-index,Java Essentials,Java Programming...