简体   繁体   English

使用 UTF-8 字符编码特殊字符

[英]Encode special characters with UTF-8 characters

I have a String Address: Mount Road (Back) [Contact-Ron] & give him the {data} I need to use SAX parser and it doesn't parse special characters, we need to replace them with UTF-8 characters.我有一个字符串Address: Mount Road (Back) [Contact-Ron] & give him the {data}我需要使用 SAX 解析器,它不解析特殊字符,我们需要用 UTF-8 字符替换它们。 Example-- & is replaced with &amp .示例&替换为&amp Is there any way to replace special characters with their corresponding UTF-8 characters without individually writing replace code?有没有什么方法可以在不单独编写替换代码的情况下用相应的UTF-8字符替换特殊字符?

You can use a library like the Apache Commons StringEscapeUtils.unescapeHtml4 to decode HTML character code sequences to corresponding UTF-8 chars.您可以使用Apache Commons StringEscapeUtils.unescapeHtml4之类的库将 HTML 字符代码序列解码为相应的 UTF-8 字符。

Take a look at https://github.com/owasp/owasp-java-encoder .看看https://github.com/owasp/owasp-java-encoder OWASP Java Encoder is easy to use and handles various safety issues. OWASP Java 编码器易于使用并处理各种安全问题。

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

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