Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert String to its Unicode code point

Tags:

java

unicode

Assuming I have a string foo = "This is an apple"

The Unicode code point equivalent will be

" \\x74\\x68\\x69\\x73.......... \\x61\\x70\\x70\\x6c\\x65 "

   T    h    i   s  ............. a    p    p    l   e

How do I convert from String foo

to

String " \\x74\\x68\\x69\\x73.......... \\x61\\x70\\x70\\x6c\\x65 "

like image 658
Computernerd Avatar asked Jun 19 '15 14:06

Computernerd


1 Answers

try this..

        public static String generateUnicode(String input) {
            StringBuilder b = new StringBuilder(input.length());
            for (char c : input.toCharArray()) {

                b.append(String.format("\\u%04x", (int) c));

            }
            return b.toString();
        }
like image 58
Hiren Avatar answered Oct 04 '22 07:10

Hiren