AKIWEB
AKIWEB

Reputation: 19612

Convert any String to UTF-8 format

I have this below String, I don't know it is in which format honestly?

Under%20\302\243100%2E00

And I need to convert the above String in UTF-8 format and the output should be like below for above String.

Under%20£100%2E00

So Basically How can I convert any String to UTF-8 format in Java?

Upvotes: 1

Views: 1164

Answers (1)

dMb
dMb

Reputation: 9337

What you have in that character sequence (which is not a Java string literal) is a mixture of two encodings: octal encoding and url encoding. Octal encoding looks like \xxx where xxx is a character code in octal. Url encoding looks like %XX where XX is a character code in hex. Octal encoding is actually part of the Java specification. Now, converting octal into a Java string isn't trivial. There is no built-in method for that. Look at this thread, though, for ideas on how to do it: How to unescape a Java string literal in Java?.

Upvotes: 2

Related Questions