我试图在scala中将字符串\u8fc8转换为"迈“。字符串\u8fc8存储为六个字符,它们是'\‘、'u’、'8‘、'f’、'c‘、'8’。
在Python中,我可以这样做:
print("\u8fc8".decode("unicode-escape"))它打印"迈",但我无法找到在Scala中实现这一点的方法,有人能帮我吗?
发布于 2018-04-27 08:07:40
"\u8fc8".format("unicode-escape")
在ScalaFiddle:如何在scala中将charCode转换为uncode中检查这个
对于"\u8fc8“,使用scala-apache unicode-string-unescape的答案要复杂一些。
def unescapeUnicode(str: String): String =
"""\\u([0-9a-fA-F]{4})""".r.replaceAllIn(str,
m => Integer.parseInt(m.group(1), 16).toChar.toString)unescapeUnicode(“u8fc8”)
检查更新的ScalaFiddle:如何在scala中将charCode转换为uncode
https://stackoverflow.com/questions/50057910
复制相似问题