vs2005/vs2008的基础应用(2)

来源:互联网 发布:sql server id自增 编辑:程序博客网 时间:2024/05/22 09:49
 创建一个HTML/HTM页面的时候为避免乱码,必须在写入的内容里面加上对输入内容编码的格式:
= ['<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();
原创粉丝点击