Replacing Of Html 5 Codes With Equivalent Characters In Java
I'm trying to replace symbols of HTML 5 using StringEscapeUtils.unescapeHtml4(), but I still have a lot of symbols which haven't been replaced such as ' ',' &'. Wha
Solution 1:
  and & aren't entities. and & are entities. If your string is really missing the ; on them, that's why they're not being decoded.
I just checked (just to be thorough!), and StringEscapeUtils.unescapeHtml4does correctly decode and &.
The correct fix is to fix whatever's giving you that string with the incomplete entities in it.
You could workaround it, also turning   and & into \u00A0 and & using String#replace after using StringEscapeUtils.unescapeHtml4:
// Ugly, technically-incorrect workaround (but we do these things sometimes)Stringresult=
StringEscapeUtils.unescapeHtml4(sourceString)
.replace(" ", "\u00A0")
.replace("&", "&");
...but it's not correct, because those aren't entities. Best to correct the string.
Post a Comment for "Replacing Of Html 5 Codes With Equivalent Characters In Java"