The following code:
org.apache.commons.lang.StringEscapeUtils.unescapeHtml("Hello World");
gives:
Hello World
But I'd like to know how to get back to the decoded string from "Hello World". I have tried the escapeHtml method, but this only enco开发者_开发百科des special characters.
But I'd like to know how to get back to the decoded string from "Hello World". I have tried the escapeHtml method, but this doesn't do anything useful.
Not true about "anything useful"; if your test string contained HTML special characters like <,>,&, the function would've turned it into < > and & (and change other upper ISO8859-1 codes into entities).
If you need to encode it back to Unicode entity format, just iterate through the String codepoints:
for (int i = 0; i < str.length(); i++)
System.out.print("&#" + str.codePointAt(i) + ";");
精彩评论