V
Vinay
Hi!
I'm trying to print a UTF-8 encoded string (called someString) such
that the output contains only US-ASCII characters. I'm doing the
following:
Charset charset = Charset.forName("US-ASCII");
CharsetEncoder encoder = charset.newEncoder();
ByteBuffer bb = null;
encoder.onUnmappableCharacter(CodingErrorAction.IGNORE);
try {
CharBuffer cb = CharBuffer.wrap(someString);
bb = encoder.encode(cb);
} catch (CharacterCodingException e) {
e.printStackTrace();
}
CharBuffer cbb = bb.asCharBuffer();
return cbb.toString();
When I give this any string all I get is a bunch of ???? so its
probably unable to map any of the characters correctly. What is the
obviously wrong thing / missing step here?
TIA
Vinay
I'm trying to print a UTF-8 encoded string (called someString) such
that the output contains only US-ASCII characters. I'm doing the
following:
Charset charset = Charset.forName("US-ASCII");
CharsetEncoder encoder = charset.newEncoder();
ByteBuffer bb = null;
encoder.onUnmappableCharacter(CodingErrorAction.IGNORE);
try {
CharBuffer cb = CharBuffer.wrap(someString);
bb = encoder.encode(cb);
} catch (CharacterCodingException e) {
e.printStackTrace();
}
CharBuffer cbb = bb.asCharBuffer();
return cbb.toString();
When I give this any string all I get is a bunch of ???? so its
probably unable to map any of the characters correctly. What is the
obviously wrong thing / missing step here?
TIA
Vinay