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.
First, NavigateToString()expect a full html document.
NavigateToString()
-, HTML HTML-, . , , unicode, .:
webBrowser1.NavigateToString("<html><body><p>ó Õ</p></body></html>");
ConvertExtendedASCII, , , . StringBuilder ( ) 800 :
ConvertExtendedASCII
StringBuilder
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(); }
. . , , :
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; }
UTF8 , NavigateToStream MemoryStream NavigateToString. UTF8, .
NavigateToStream
MemoryStream
NavigateToString
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.
System.String
Source: https://habr.com/ru/post/1769951/More articles:Which server is best for image hosting? - asp.netunhighlight uitabbaritem in uitabbarcontroller - iphoneGet session contents from a dump of an ASP.net 3.5 process in Windbg - asp.netWhy is there a 50 percent chance of finding the key in half the attempts in the brute force of the attack on the symmetric algorithm? - cryptographyImage processing through a standalone application - javaHow to switch from C ++ to Java? - javaHow to disable tabbaritem - iphoneKeep "password ok" in php session variable? - javascriptiPhone: UITabBar custom image not working - objective-cobjective-c touch-events - event-handlingAll Articles