开发者

Encoding in Java

I have a string with special characters in Java.

"[^\\"]*\\"

I want to convert it to HTML entities like this:

"[^\\"]*\\"

How this could 开发者_高级运维be achieved in Java?


Apache Commons Lang includes a helper for encoding HTML. StringEscapeUtils.escapeHtml() should do the trick. According to the javadocs it "Supports all known HTML 4.0 entities, including funky accents".


Use String.replace() as needed:

"[^\\\"]*\\".replace("\"", """);


You need to parse the input string character by character and look for particular ones that you want to convert. When you find a match, simply replace that character with the HTML entity.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜