Click here to Skip to main content
15,881,938 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a string which contains "C3A1" which is the utf-8 equivalent of á
How do I convert this to á in Java.

What I have tried:

I've tried some ways to parse it as a char but nothing's worked
Posted
Updated 18-Jul-18 12:02pm

If you have a byte array representing an UTF-8 string use the Java String constructor accepting a byte array and an encoding:
Java
String str = new String(utf8Bytes, "UTF-8");
If you really have a String object containing an UTF-8 string, you have to convert it first to a byte array:
Java
byte[] utf8Bytes = inputStr.getBytes("ISO-8859-1");
You can use any full 8-bit encoding in the above. It is just used to ensure that each single byte from the input string is copied to the byte array.
 
Share this answer
 
Quote:
How do I convert this to á in Java.

As is, this is non sense.
As 'á' is not ASCII, you need to understand a few things:
- what is ascii code
- what is ascii with codepages
- what is UTF encoding and UTF8
- you need to understand how Java handle char encoding.

Then you will decide what encoding you will use in your code. depending on encoding, the char is not the same.
Quote:
I've tried some ways to parse it as a char but nothing's worked

You only haven't show what you have done.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900