Search code examples
javaandroidhtml-encode

Android: HTML encoder


I have html text that I want to show in webview.

As specification, data must be URI-escaped. So I tried to use URLEncoder.encode() function, but that will not help me, as it converts blank space with plus sign.

So is there any encoding function available?


Solution

  • As @Seb said, I created my own function that worked for me:

    public String encodeHTML(String s)
    {
        s = s.replaceAll("#", "%23");
        s = s.replaceAll("%", "%25");
        return s;
    }
    

    Any improvement in this approach will be appreciated.