Cus*_*ard 2 java encoding html-entities
以下代码:
org.apache.commons.lang.StringEscapeUtils.unescapeHtml("Hello World");
Run Code Online (Sandbox Code Playgroud)
得到:
Hello World
Run Code Online (Sandbox Code Playgroud)
但是我想知道如何从"Hello World"回到已解码的字符串.我尝试过escapeHtml方法,但这只编码特殊字符.
但是我想知道如何从"Hello World"回到已解码的字符串.我试过了escapeHtml方法,但这没有做任何有用的事情.
关于"有用的东西"不正确; 如果您的测试字符串包含HTML特殊字符,如<,>,&,则该函数会将其转换为< > 和& (并将其他上层ISO8859-1代码更改为实体).
如果需要将其编码回Unicode实体格式,只需遍历String代码点:
for (int i = 0; i < str.length(); i++)
System.out.print("&#" + str.codePointAt(i) + ";");
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
750 次 |
| 最近记录: |