创建一个HTML/HTM页面的时候为避免乱码,必须在写入的内容里面加上对输入内容编码的格式:
a = [ ' <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> ' ,
' <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> ' ,
' <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> '
]
匹配: " <meta[ ]+http-equiv=["']?content-type["']?[ ]+content=["']?text/html;[ ]*charset=([0-9-a-zA-Z]+)["']? "
下面是创建一个HTML/HTM页面的c#代码:
if (File.Exists(HttpContext.Current.Server.MapPath("test.html")))
{
File.Delete(HttpContext.Current.Server.MapPath("test.html"));
}
FileStream fs = File.Create(HttpContext.Current.Server.MapPath("test.html"));
Byte[] info = new UTF8Encoding(true).GetBytes("<html><head><meta http-equiv='Content-Type' content='text/html;charset=utf-8'></head><body><h1>测试1HTML,编码正常了!</h1></body></html>");
fs.Write(info, 0, info.Length);
fs.Close();
a = [ ' <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> ' ,
' <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> ' ,
' <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> '
]
匹配: " <meta[ ]+http-equiv=["']?content-type["']?[ ]+content=["']?text/html;[ ]*charset=([0-9-a-zA-Z]+)["']? "
下面是创建一个HTML/HTM页面的c#代码:
if (File.Exists(HttpContext.Current.Server.MapPath("test.html")))
{
File.Delete(HttpContext.Current.Server.MapPath("test.html"));
}
FileStream fs = File.Create(HttpContext.Current.Server.MapPath("test.html"));
Byte[] info = new UTF8Encoding(true).GetBytes("<html><head><meta http-equiv='Content-Type' content='text/html;charset=utf-8'></head><body><h1>测试1HTML,编码正常了!</h1></body></html>");
fs.Write(info, 0, info.Length);
fs.Close();