简体   繁体   English

如何将Unicode字符转换为Java中的实际字符?

[英]how to convert unicode characters to actual characters in java?

I have to two strings : 1. bookkeeping forms \\\& templates 2. hodgkin\'s disease 我要输入两个字符串:1.簿记表格2.霍奇金病

I want to replace \\\& with & and \' with '. 我想用&替换\\\\ u0026并用'替换\\ u0027。 One of the way is replace their occurrence with corresponding symbol but is there a generic way to deal with this problem ? 一种方法是用相应的符号替换它们的出现,但是有没有通用的方法来解决此问题?

My recommendation is Apache StringScapeUtils specifically the unescapeJava method. 我的建议是Apache StringScapeUtils特别是unescapeJava方法。

Site: https://commons.apache.org/proper/commons-lang/ 网站: https //commons.apache.org/proper/commons-lang/

Maven repo: https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 Maven回购: https : //mvnrepository.com/artifact/org.apache.commons/commons-lang3

在此处输入图片说明

That method converts unicode to readable text, for example: 该方法将unicode转换为可读文本,例如:

String stringWithUnicode; //For example "tendr\\u00e1"
StringScapeUtils.unescapeJava(stringWithUnicode); //This call returns: Tendrá

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM