我想转换String成int.
例如:
如果String是"0x1F60A"那么它应该转换为int与0x1F60A
String str = "0x1F60A";
int i = 0x1F60A; // it must be something like this.
Run Code Online (Sandbox Code Playgroud)
为什么我需要这个。因为我要将 unicode int 转换为 Emoji,所以我正在使用此代码。
final String emojiString = str.substring(start,end);
// value in emojiString is 0x1F60A
int unicode = // need to convert this string into int
ss.replace(start, end, new String(Character.toChars(unicode)));
Run Code Online (Sandbox Code Playgroud)
你能告诉我我该怎么做吗?
Unicode 到 Int 的转换:
你必须省略第2一个字符.substring(2)
int code = Integer.parseInt(unicodeStr.substring(2), 16);
Run Code Online (Sandbox Code Playgroud)
将 String 转换为 int:
try {
myNum = Integer.parseInt(myString);
} catch(NumberFormatException nfe) {
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
151 次 |
| 最近记录: |