converting String from UTF8 to ascii format

hi all,I have String in UTF8 formathow can display it in ascii format.ThanksJAmol
[116 byte] By [JAmola] at [2007-10-2 10:56:26]
# 1
> hi all,>I have String in UTF8 format>how can display it in ascii format.> > Thanks> JAmolStrings are UNICODE not ASCII or UTF8.
sabre150a at 2007-7-13 3:21:32 > top of Java-index,Java Essentials,Java Programming...
# 2

> hi all,

>I have String in UTF8 format

>how can display it in ascii format.

>

No you don't. If it's in UTF-8 it's bytes, not characters. What you might have is the kind of mess you get loading a string from a file with the wrong encoding. If so then change the way you read the data rather than trying to fix it once loaded.

In general, if you're specifying an specific encoding, use InputStreamReader, wrapped arround a FileInputStream if necessary.

malcolmmca at 2007-7-13 3:21:32 > top of Java-index,Java Essentials,Java Programming...
# 3

> hi all,

>I have String in UTF8 format

>how can display it in ascii format.

>

If the String contains only ASCII characters , then UTF-8 bytes and ASCII bytes are the same.

If the String does not contain only ASCII characters, then you cannot "display it in ascii format".

da.futta at 2007-7-13 3:21:32 > top of Java-index,Java Essentials,Java Programming...
# 4

Hi friends,

Thanks for your replies,

well still my doubt is not clear,

I am doing same thing, this guy in following link is doing,

http://www-304.ibm.com/jct09002c/isv/tech/faq/individual.jsp?oid=1:78875

and as per their discussion I need to convert string format,

kindly help me

JAmol

JAmola at 2007-7-13 3:21:32 > top of Java-index,Java Essentials,Java Programming...
# 5

Sounds like the Directory Server is returning a faulty string. You get this with some databases too. The may have taken a UTF-8 byte stream and converted it as if it were ISO-Latin-1.

In these cases:

1) Complain.

2) You can rescue the characters as;

String fixedString = new String(duffString.getBytes("ISO-8859-1"), "UTF-8");

This converts the data back to a byte array and then decodes it correctly.

malcolmmca at 2007-7-13 3:21:32 > top of Java-index,Java Essentials,Java Programming...