Convert string to unicode [duplicate]

倖福魔咒の 提交于 2020-08-05 05:37:13

问题


i want convert a simple text like, "my simple text" to Unicode character in Android.

for example this :

"\u0628\u0631\u0646\u0627\u0645\u0647 \u0646\u0648\u06cc\u0633\u06cc"

this string in uni code is :

برنامه نویسی

i want input

برنامه نویسی

and response

"\u0628\u0631\u0646\u0627\u0645\u0647 \u0646\u0648\u06cc\u0633\u06cc"

this string . please help me .


回答1:


Android native its java, so.. check this:

You can do it for any Java char using the one liner here:

System.out.println( "\\u" + Integer.toHexString('÷' | 0x10000).substring(1) );

Reference: Get unicode value of a character

I hope that I have helped answer some of your questions.




回答2:


Use Apache Commons Lang api. StringEscapeUtils.escapeJava() can help you get the answer.

import org.apache.commons.lang3.StringEscapeUtils;

public class StringUnicode {

    public static void main(String[] args) {

        String foreignText = "برنامه نویسی";

        String response = StringEscapeUtils.escapeJava(foreignText);
        System.out.println(response);
    }
}


来源:https://stackoverflow.com/questions/33871966/convert-string-to-unicode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!