Shubham Garg
Shubham Garg

Reputation: 47

how to convert unicode characters to actual characters in java?

I have to two strings : 1. bookkeeping forms \\u0026 templates 2. hodgkin\u0027s disease

I want to replace \\u0026 with & and \u0027 with '. One of the way is replace their occurrence with corresponding symbol but is there a generic way to deal with this problem ?

Upvotes: 2

Views: 2286

Answers (1)

Ele
Ele

Reputation: 33736

My recommendation is Apache StringScapeUtils specifically the unescapeJava method.

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

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

enter image description here

That method converts unicode to readable text, for example:

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

Upvotes: 3

Related Questions