我想把html里边某些标记字符 比如[news] 替换成数据库中取出来的字符 请问如何做  麻烦各位高手讲解下。。谢谢

解决方案 »

  1.   

    先读取模板页,然后用replace替换即可
      

  2.   

    使用模板替换
    public static bool WriteFile(string strText) 
        { 
            string path = HttpContext.Current.Server.MapPath("Html/"); 
            System.Text.Encoding code = System.Text.Encoding.GetEncoding("gb2312"); 
            string temp = HttpContext.Current.Server.MapPath("Html/A.html"); 
            StreamReader sr = null; 
            StreamWriter sw = null; 
            string str = ""; 
            try 
            { 
                sr = new StreamReader(temp, code); 
                str = sr.ReadToEnd(); 
            } 
            catch (Exception exp) 
            { 
                HttpContext.Current.Response.Write(exp.Message); 
                HttpContext.Current.Response.End(); 
                sr.Close(); 
            } 
            string htmlfilename = DateTime.Now.ToString("yyyyMMddHHmmss") + ".html"; 
            try 
            { 
                sw = new StreamWriter(path + htmlfilename, false, code); 
                sw.Write(str); 
                sw.Flush(); 
            } 
            catch (Exception ex) 
            { 
                HttpContext.Current.Response.Write(ex.Message); 
                HttpContext.Current.Response.End(); 
            } 
            finally 
            { 
                sw.Close(); 
            } 
            return true; 
        }