http://www.exampledepot.com/egs/java.nio.charset/ConvertChar.html
Amit Jain
> Hi,
> I've got a String, which charset is e.g. ISO 8859-1:
>
> String myString;
Not really. You've got a String that consists of Unicode characters.
(UTF-16 characters, to be very precise.) All strings in Java are Unicode.
What you probalby mean is that you have a String that was initially created
from bytes that were encoded in ISO 8859-1.
> and I'd like to convert it to another charset, e.g. ISO 8859-2.
> How to do it?
byte[] iso88592Bytes = myString.getBytes("ISO-8859-2");
assuming that your JRE supports 8859-2 If not, this will throw an
UnsupportedEncodingException. Here's a handy program to list all of the
encodings Java supports:
import java.util.*;
import java.nio.charset.*;
class Charsets
{
public static void main(String[] args)
{
List names = new ArrayList();
Iterator cs = Charset.availableCharsets().values().iterator() ;
while (cs.hasNext())
{
names.add(((Charset)cs.next()).name());
}
Collections.sort(names);
Iterator nameIter = names.iterator() ;
while (nameIter.hasNext())
{
System.out.println(nameIter.next());
}
}
}
mehafi@gmail.com - 04 Aug 2007 10:15 GMT
Thans to all for your posts.
Becauose ISO-8859-1 and ISO-8859-2 are difrent only on 6 positions
( meaning polish national characters ) I wrote a code, which:
1) convert String to StringBuffer,
2) searching in StringBuffer this 6 characters and repleacing them
witch propper charset
Oliver Wong - 07 Aug 2007 15:29 GMT
> Thans to all for your posts.
> Becauose ISO-8859-1 and ISO-8859-2 are difrent only on 6 positions
> ( meaning polish national characters ) I wrote a code, which:
> 1) convert String to StringBuffer,
> 2) searching in StringBuffer this 6 characters and repleacing them
> witch propper charset
Your program is probably buggy then. It may work on YOUR particular
computer, but it may not work when moved onto another computer where the
default encodings differ. Re-read Mike Schiling's post, particularly the
part that goes:
<quote>
All strings in Java are Unicode.
What you probalby mean is that you have a String that was initially
created
from bytes that were encoded in ISO 8859-1.
</quote>
Given your problem description, your best bet is probably not to use
the String class at all, and work entirely with byte[].
- Oliver
>Hi,
>I've got a String, which charset is e.g. ISO 8859-1:
[quoted text clipped - 3 lines]
>and I'd like to convert it to another charset, e.g. ISO 8859-2.
>How to do it?
See http://mindprod.com/jgloss/native2ascii.html
http://mindprod.com/jgloss/encoding.html
http://mindprod.com/jgloss/conversion.html

Signature
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com