java - 如何将数字的 Unicode 转换为 Java 中的数字本身?

标签 java unicode

如何在 Java 中将数字的 Unicode 转换为数字本身?

char c ='2';
int x =c;
// here x=unicode of 2, how can I put the 2 itself in x?

最佳答案

最通用的解决方案是

int x = Character.digit(c, 10); // interpret c as a digit in base 10

最快的解决方案是

int x = c - '0'; // subtracts the Unicode representation of '0' from c

关于java - 如何将数字的 Unicode 转换为 Java 中的数字本身?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13884380/

相关文章:

python - Python解析JSON : how do I get has_key() working again after a change of format?

regex - 替换给定 unicode 字符串中的所有表情符号

java - 比较两个 JSON

java - 尝试释放内存时出现 EXCEPTION_ACCESS_VIOLATION (0xc0000005)

java - 发生重新哈希时,存储桶的索引是否会发生变化?

java - 从文本文件 :  读取的第一个字符

java - 从数据库获取 Unicode 文本后,如何将其存储在文件中?

java - 使用 Aqua 外观禁用 JInternalFrames 周围的阴影

java - 如何快速得到计数结果?

java - Java 小程序中的 Unicode/日语字符