乱码!现将待处理网页代码写入文本,之后对此htm网页代码进行查找替换,并保存,可为什么再打开时中文全乱码!?
先通过如下代码,将htm网页中的代码全读出来StreamReader sr = new StreamReader(Application.StartupPath + @"\crowdDialogue.html", Encoding.GetEncoding("gb2312"))
string tmp = sr.ReadToEnd();
之后对原htm网页代码中的标志字符串<!--TTTTXXXX****-->进行查找替换
string b = @"<!--TTTTXXXX****-->";
string c = @"<p>----2013年12月12日 14:13:22----<br />";
tmp = tmp.Replace(b, c);
StreamWriter sw = new StreamWriter(Application.StartupPath + @"\crowdDialogue1.html");
sw.Write(tmp);
sw.Close();
最后将新网页打出来
webBrowser1.Navigate(Application.StartupPath + @"\crowdDialogue1.html");
可为什么中文全乱码???
webbrowser 乱码 htm htm C# --------------------编程问答-------------------- crowdDialogue1.html
这个文件内容加入mata头 charset=gb2312 --------------------编程问答-------------------- 版本不对吧?? --------------------编程问答--------------------
你好,在原htm网页代码中mata头 charset=gb2312有了,仅替换<!--TTTTXXXX****-->
<html>--------------------编程问答--------------------
<head>
<title>XiaoXin</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"><style type="text/css">
<!--
body {
margin-left: 10px;
width: 150px;
line-height: 12pt;
font-size: 9pt;
}
-->
</style><head>
<body>
<!--TTTTXXXX****-->
</body>
</html>
对不起啊,刚应用错了 --------------------编程问答--------------------
你好,不明白,请教? --------------------编程问答-------------------- StreamReader 和 StreamWriter 都会涉及到编码,你可以试试给StreamWriter加上gb2312的编码限制。
如果还不行,可以尝试下把编码都改成UTF8 --------------------编程问答-------------------- charset 不对,看下那个 HTML 的编码 --------------------编程问答-------------------- 我老师曾经教过我,右键,编码,改一下 --------------------编程问答-------------------- 只要保证你的所有编码统一就OK啦 --------------------编程问答-------------------- string b = @"<!--TTTTXXXX****-->";
string c = @"<p>----2013年12月12日 14:13:22----<br />";
tmp = tmp.Replace(b, c);
StreamWriter sw = new StreamWriter(Application.StartupPath + @"\crowdDialogue1.html");
sw.Write(tmp);
sw.Close();
注意你的StreamWriter sw = new StreamWriter(Application.StartupPath + @"\crowdDialogue1.html");这行代码应该也要添上响应的编码
StreamWriter sw = new StreamWriter(Application.StartupPath + @"\crowdDialogue1.html",Encoding.GetEncoding("gb2312"));
补充:.NET技术 , C#