题目
解题思路
- 利用String自带的替换方法对指定字符进行替换;
- 注意事项:
- 部分特殊字符需要用转义字符;
- 需要将“与符号”放置到最后转换避免造成二次转换。
代码展示
class Solution {
public String entityParser(String text) {
text = text.replaceAll(""", "\"");
text = text.replaceAll("'", "'");
text = text.replaceAll(">", ">");
text = text.replaceAll("<", "<");
text = text.replaceAll("⁄", "/");
text = text.replaceAll("&", "&");
return text;
}
}