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}就自动替换成需要的内容?
如果能有一个好的实例,本人感激不敬将分送上。
<strong>友情链接:</strong>
<#list links as link>
<a href="${link.linkUrl}" target="_blank" title="${link.linkName}">${link.linkName}</a> 比如这段程序,这只是其中小段,请问如何让程序到了${link.linkUrl}、${link.linkName}就自动替换成需要的内容?
如果能有一个好的实例,本人感激不敬将分送上。
然后String.Replace("${link.linkUrl}","www.baidu.com");或者如果你的字符串时符合w3c标准的,就可以用Xml来解析
渠道你需要的节点,然后修改属性就OK.
楼主想得到效果,不用理会这个的说?
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();
}
}
看看IWMS, Discuz模板引擎
参考
MatchCollection maths = Regex.Matches(mobandata, str);
foreach(Match match in maths)
{ }
程序不会进入foreach啊。。到底怎么写?