问题
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