WP7 WebBrowser.NavigateToString () and text encoding

Does anyone know how to load a UTF8 encoded string using the WebBrowser.NavigateToString () method? At the moment, I'm finishing a bunch of incorrectly displayed characters.

Here is a simple line that will not display correctly:

webBrowser.NavigateToString("ąęłóńżźćś");

The code file is saved with UTF-8 encoding (with signature).

Thank.

+3
source share
4 answers

First, NavigateToString()expect a full html document.

-, HTML HTML-, . , , unicode, .
:

webBrowser1.NavigateToString("<html><body><p>&oacute; &#213;</p></body></html>");
+3

ConvertExtendedASCII, , , . StringBuilder ( ) 800 :

public string FixHtml(string HTML)
{
    StringBuilder sb = new StringBuilder();
    char[] s = HTML.ToCharArray();
    foreach (char c in s)
    {
        if (Convert.ToInt32(c) > 127)
            sb.Append("&#" + Convert.ToInt32(c) + ";");
        else
            sb.Append(c);
    }
    return sb.ToString();
}
+4

. . , , :

private static string ConvertExtendedASCII(string HTML)
{
    string retVal = "";
    char[] s = HTML.ToCharArray();

    foreach (char c in s)
    {
        if (Convert.ToInt32(c) > 127)
            retVal += "&#" + Convert.ToInt32(c) + ";";
        else
            retVal += c;
    }

    return retVal;
}
+1

UTF8 , NavigateToStream MemoryStream NavigateToString. UTF8, .

Note that the line in the question is not a UTF8 line. This is a UTF16 string with some garbage. Putting zeros between bytes and storing them in System.String, you messed it up.

0
source

Source: https://habr.com/ru/post/1769951/


All Articles