div class="link"> 
     <strong>友情链接:</strong> 
     <#list links as link> 
  <a href="${link.linkUrl}" target="_blank" title="${link.linkName}">${link.linkName}</a> 比如这段程序,这只是其中小段,请问如何让程序到了${link.linkUrl}、${link.linkName}就自动替换成需要的内容?
如果能有一个好的实例,本人感激不敬将分送上。

解决方案 »

  1.   

    吧你的这个东东看成是一个String
    然后String.Replace("${link.linkUrl}","www.baidu.com");或者如果你的字符串时符合w3c标准的,就可以用Xml来解析
    渠道你需要的节点,然后修改属性就OK.
      

  2.   

    ${link.linkName}这个貌似是调用了某一个方法获得的吧?
    楼主想得到效果,不用理会这个的说?
      

  3.   

    string str = @"${(.*?)}"; 
    MatchCollection maths = Regex.Matches(mobandata, str);   
    foreach(Match match in maths) 
    { } 
    通过正则替换

     public static string CreatHtmlPage(string Title, string Time, string Author, string Content) 
        { 
            string mbPath = System.Web.HttpContext.Current.Server.MapPath("~/template.htm"); 
            Encoding code = Encoding.GetEncoding("gb2312"); 
            StreamReader sr = null; 
            StreamWriter sw = null; 
            string str = null; 
            try 
            { 
                sr = new StreamReader(mbPath, code); 
                str = sr.ReadToEnd();         } 
            catch (Exception ex) 
            { 
                throw ex; 
            } 
            finally 
            { 
                sr.Close(); 
            } 
            string fileName = DateTime.Now.ToString("yyyyMMddHHmmss") + ".htm"; 
            str = str.Replace("$title$", Title);
            try 
            { 
                DirectoryInfo di = new DirectoryInfo(System.Web.HttpContext.Current.Server.MapPath("~/Html/")); 
                try 
                { 
                    if (di.Exists) 
                    {                 } 
                    else 
                    { 
                        di.Create(); 
                    }             } 
                catch (Exception ex) 
                { 
                    throw new Exception(ex.Message); 
                } 
                sw = new StreamWriter(System.Web.HttpContext.Current.Server.MapPath("~/Html/") + fileName, false, code); 
                sw.Write(str); 
                sw.Flush(); 
                return "~/Html/" + fileName; 
            } 
            catch (Exception ex) 
            { 
                throw ex; 
            } 
            finally 
            { 
                sw.Close(); 
            } 
        } 
      

  4.   

    一般使用模板,通过函数绑定数据
    看看IWMS, Discuz模板引擎
    参考
      

  5.   

    string str = @"${(.*?)}"; 
    MatchCollection maths = Regex.Matches(mobandata, str);  
    foreach(Match match in maths) 
    { } 
    程序不会进入foreach啊。。到底怎么写?
      

  6.   

    程序不会进入foreach 那是你正则没写好 没匹配到东西