Noor
Noor

Reputation: 20178

Java Unicode characters to UTF

In Java, how can I convert a string containing unicode characters escaped to utf 8, e.g. from Rüppell's_Vulture to R%c3%bcppell's_Vulture

Upvotes: 0

Views: 264

Answers (2)

Joop Eggen
Joop Eggen

Reputation: 109613

String s = URLDecoder.decode("R%c3%bcppell's_Vulture", "UTF-8");
String s = URLEncoder.encode("Rüppell's_Vulture", "UTF-8");

With % it is an URL encoding.

Upvotes: 1

3yakuya
3yakuya

Reputation: 2672

Copy it to byte array with getBytes("UTF-8). Like this:

byte[] utf = String.getBytes("UTF-8")

Do not know the way of dealing with it just with Strings (I believe they have fixed encoding).

Upvotes: 0

Related Questions