How to remove hard spaces with Jsoup?

前端 未结 2 1561
南旧
南旧 2021-01-11 11:13

I\'m trying to remove hard spaces (from   entities in the HTML). I can\'t remove it with .trim() or .replace(\" \", \"\"), et

2条回答
  •  时光说笑
    2021-01-11 11:39

    The question has been edited to reflect the true problem.

    New answer; The hardspace, ie. entity   (Unicode character NO-BREAK SPACE U+00A0 ) can in Java be represented by the character \u00a0, thus code becomes, where str is the string gotten from the text() method

    str.replaceAll ("\u00a0", "");
    

    Old answer; Using the JSoup library,

    import org.jsoup.parser.Parser;
    
    String str1 = Parser.unescapeEntities("last week, Ovokerie Ogbeta", false);
    String str2 = Parser.unescapeEntities("Entered » Here", false);
    System.out.println(str1 + " " + str2);
    

    Prints out:

    last week, Ovokerie Ogbeta Entered » Here 
    

提交回复
热议问题