How to unescape HTML character entities in Java?

前端 未结 11 1756
耶瑟儿~
耶瑟儿~ 2020-11-21 22:38

Basically I would like to decode a given Html document, and replace all special chars, such as \" \" -> \" \", \">\" -

11条回答
  •  遇见更好的自我
    2020-11-21 23:09

    In my case i use the replace method by testing every entity in every variable, my code looks like this:

    text = text.replace("Ç", "Ç");
    text = text.replace("ç", "ç");
    text = text.replace("Á", "Á");
    text = text.replace("Â", "Â");
    text = text.replace("Ã", "Ã");
    text = text.replace("É", "É");
    text = text.replace("Ê", "Ê");
    text = text.replace("Í", "Í");
    text = text.replace("Ô", "Ô");
    text = text.replace("Õ", "Õ");
    text = text.replace("Ó", "Ó");
    text = text.replace("Ú", "Ú");
    text = text.replace("á", "á");
    text = text.replace("â", "â");
    text = text.replace("ã", "ã");
    text = text.replace("é", "é");
    text = text.replace("ê", "ê");
    text = text.replace("í", "í");
    text = text.replace("ô", "ô");
    text = text.replace("õ", "õ");
    text = text.replace("ó", "ó");
    text = text.replace("ú", "ú");
    

    In my case this worked very well.

提交回复
热议问题