代码:HTML code<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>无标题页</title>
<style type="text/css">
<!--
.list{padding:10px;font-size:13px;line-height:20px;}
.list .list_title{height:30px;line-heigh:25px;color:black;font-size:12pt;border-bottom:solid 1px gray; background:#cccccc;}
-->
</style>
</head>
<body>
<form id="form1">
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td>菜单文件</td>
</tr>
</table>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td align="left" valign="top" class="list">
<div class="list_title">国内大事<a href=''> 更多</a></div>
{ylcms:news type="11" number="20"}
<div>
国内大事<a href="(ylcms:Url/)">(ylcms:Title/)</a><span>(ylcms:Date/)</span>
</div>
<br />
{/ylcms}
</td>
<td align="left" valign="top" class="list">
<div class="list_title">国外大事<a href=''> 更多</a></div>
{ylcms:message type="11" number="20"}
<div>
国外大事<a href="(ylcms:Url/)">(ylcms:Title/)</a><span>(ylcms:Date/)</span>
</div>
<br />
{/ylcms}
</td>
</tr>
<tr>
<td align="left" valign="top" class="list">
<div class="list_title">军事新闻<a href=''> 更多</a></div>
{ylcms:list type="11" number="20"}
<div>
军事新闻<a href="(ylcms:Url/)">(ylcms:Title/)</a><span>(ylcms:Date/)</span>
</div>
<br />
{/ylcms}
</td>
<td align="left" valign="top" class="list">
<div class="list_title">财经新闻<a href=''> 更多</a></div>
{ylcms:notice type="11" number="20"}
<div>
财经新闻<a href="(ylcms:Url/)">(ylcms:Title/)</a><span>(ylcms:Date/)</span>
</div>
<br />
{/ylcms}
</td>
</tr>
</table>
</form>
</body>
</html>C# code
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using System.IO;
protected void ButtonAll_Click(object sender, EventArgs e)
{
//以下是标签库
ArrayList a1 = new ArrayList();//起始标签
a1.Add("{ylcms:news");
a1.Add("{ylcms:message");
a1.Add("{ylcms:list");
a1.Add("{ylcms:notice");//现在模板只调用了以上四个,
a1.Add("{ylcms:pic");
a1.Add("{ylcms:link");
a1.Add("{ylcms:aaaa");
a1.Add("{ylcms:bbbb");
ArrayList a2 = new ArrayList();//结束标签
a2.Add("{/ylcms}");
a2.Add("{/ylcms}");
a2.Add("{/ylcms}");
a2.Add("{/ylcms}");
a1.Add("{/ylcms}");
a1.Add("{/ylcms}");
a1.Add("{/ylcms}");
a1.Add("{/ylcms}"); string TemplatePath = HttpContext.Current.Server.MapPath("../template/index.htm");//取模板
Encoding Code = Encoding.GetEncoding("gb2312");//定义编码方式
StreamReader ReaderFile = null;
string strFile =string.Empty;
ReaderFile = new StreamReader(TemplatePath, Code);//读出模板内容
strFile = ReaderFile.ReadToEnd();
ReaderFile.Close();
ReaderFile.Dispose(); string strss = "";//等每组标签内的内容
string strTemplateLabel = "";
for (int i = 0; i < a1.Count; i++)//特环标签库
{
int intStart = strFile.IndexOf(a1[i].ToString());
int intEnd = strFile.IndexOf(a2[i].ToString()) +a2[i].ToString().Length;
strss += strTemplateLabel+"<hr>";
}
alnewContent.Clear();
a1.Clear();
a2.Clear();
Response.Write(strss);补充一下:我想要取出每个{ ........}之间的数据.
结果显示如下:
{ylcms:notice type="11" number="20"}
<div>
财经新闻<a href="(ylcms:Url/)">
(ylcms:Title/)</a>
<span>(ylcms:Date/)</span>
</div>
{/ylcms}
.......
请各位高手帮忙一下,谢谢谢谢
<head>
<title>无标题页</title>
<style type="text/css">
<!--
.list{padding:10px;font-size:13px;line-height:20px;}
.list .list_title{height:30px;line-heigh:25px;color:black;font-size:12pt;border-bottom:solid 1px gray; background:#cccccc;}
-->
</style>
</head>
<body>
<form id="form1">
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td>菜单文件</td>
</tr>
</table>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td align="left" valign="top" class="list">
<div class="list_title">国内大事<a href=''> 更多</a></div>
{ylcms:news type="11" number="20"}
<div>
国内大事<a href="(ylcms:Url/)">(ylcms:Title/)</a><span>(ylcms:Date/)</span>
</div>
<br />
{/ylcms}
</td>
<td align="left" valign="top" class="list">
<div class="list_title">国外大事<a href=''> 更多</a></div>
{ylcms:message type="11" number="20"}
<div>
国外大事<a href="(ylcms:Url/)">(ylcms:Title/)</a><span>(ylcms:Date/)</span>
</div>
<br />
{/ylcms}
</td>
</tr>
<tr>
<td align="left" valign="top" class="list">
<div class="list_title">军事新闻<a href=''> 更多</a></div>
{ylcms:list type="11" number="20"}
<div>
军事新闻<a href="(ylcms:Url/)">(ylcms:Title/)</a><span>(ylcms:Date/)</span>
</div>
<br />
{/ylcms}
</td>
<td align="left" valign="top" class="list">
<div class="list_title">财经新闻<a href=''> 更多</a></div>
{ylcms:notice type="11" number="20"}
<div>
财经新闻<a href="(ylcms:Url/)">(ylcms:Title/)</a><span>(ylcms:Date/)</span>
</div>
<br />
{/ylcms}
</td>
</tr>
</table>
</form>
</body>
</html>C# code
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using System.IO;
protected void ButtonAll_Click(object sender, EventArgs e)
{
//以下是标签库
ArrayList a1 = new ArrayList();//起始标签
a1.Add("{ylcms:news");
a1.Add("{ylcms:message");
a1.Add("{ylcms:list");
a1.Add("{ylcms:notice");//现在模板只调用了以上四个,
a1.Add("{ylcms:pic");
a1.Add("{ylcms:link");
a1.Add("{ylcms:aaaa");
a1.Add("{ylcms:bbbb");
ArrayList a2 = new ArrayList();//结束标签
a2.Add("{/ylcms}");
a2.Add("{/ylcms}");
a2.Add("{/ylcms}");
a2.Add("{/ylcms}");
a1.Add("{/ylcms}");
a1.Add("{/ylcms}");
a1.Add("{/ylcms}");
a1.Add("{/ylcms}"); string TemplatePath = HttpContext.Current.Server.MapPath("../template/index.htm");//取模板
Encoding Code = Encoding.GetEncoding("gb2312");//定义编码方式
StreamReader ReaderFile = null;
string strFile =string.Empty;
ReaderFile = new StreamReader(TemplatePath, Code);//读出模板内容
strFile = ReaderFile.ReadToEnd();
ReaderFile.Close();
ReaderFile.Dispose(); string strss = "";//等每组标签内的内容
string strTemplateLabel = "";
for (int i = 0; i < a1.Count; i++)//特环标签库
{
int intStart = strFile.IndexOf(a1[i].ToString());
int intEnd = strFile.IndexOf(a2[i].ToString()) +a2[i].ToString().Length;
strss += strTemplateLabel+"<hr>";
}
alnewContent.Clear();
a1.Clear();
a2.Clear();
Response.Write(strss);补充一下:我想要取出每个{ ........}之间的数据.
结果显示如下:
{ylcms:notice type="11" number="20"}
<div>
财经新闻<a href="(ylcms:Url/)">
(ylcms:Title/)</a>
<span>(ylcms:Date/)</span>
</div>
{/ylcms}
.......
请各位高手帮忙一下,谢谢谢谢
解决方案 »
- 求 PluginInstaller.msi for vs2003 下载地址
- 求一个在C#中的SQL语句.
- 100分求购 asp.net2.0 发送email的源码,在线等
- 怎么在VS.NET2005 下把程序生成的EXE文件设置成能在framework1.1 下执行的呢!在线等
- 面向对象继承的问题
- 如何取到指定frame内的纯文字内容?
- 关于DataTable的事件响应问题!
- 请问在一个Windows 表单程序中,如何实现单击F1键,弹出一个对话框?
- DataGrid中的列标题如何居中
- 关于webQQ起名,在此结帖(一)
- c#中更新MongoDB的数据
- 非静态的字段、方法或属性“WindowsFormsApplication1.DataOperate.getCom(string)”要求对象引用
string str = File.ReadAllText(@"E:\1.txt", Encoding.GetEncoding("gb2312"));
Regex reg = new Regex(@"(?is)\{ylcms[^\}]+?\}.*?\{/ylcms\}");
foreach (Match m in reg.Matches(str))
{
Console.WriteLine(m.Value);
Console.WriteLine(); Console.WriteLine(); Console.WriteLine(); Console.WriteLine();
}
MatchCollection matches = Regex.Matches("your html", @"(\{ylcms[^\}]*?\}[^\{]*?\{/ylcms\})", RegexOptions.IgnoreCase);
foreach (Match match in matches)
{
Console.WriteLine(match.Groups[1].Value);
}
string str = File.ReadAllText(@"E:\1.txt", Encoding.GetEncoding("gb2312"));
Regex reg = new Regex(@"(?is)\{[^\}]+?\}.*?}");
foreach (Match m in reg.Matches(str))
{
Console.WriteLine(m.Value);
Console.WriteLine(); Console.WriteLine(); Console.WriteLine(); Console.WriteLine();
}
老师您好:
刚才在那边你用这种方法
Regex reg = new Regex(@"(?is)\{ylcms[^\}]+?\}((?!\{/?ylcms).)*{/ylcms\}");
帮我得出了页面上所有 {ylcms:.....}.....{/ylcms}的标签内容.可是把我的 {ylcms:pagetitle/}
这个标签过滤掉了,我想要一起显示出来,
比如页面上有:
<table border="0" cellpadding="0" cellspacing="0">
<tr><td>{ylcms:title /ylcms}</td>
<td align="left" valign="top" class="list">
<div class="list_title">国内大事<a href=''> 更多</a></div>
{ylcms:news type="11" number="20"}
<div>
国内大事<a href="(ylcms:Url/)">(ylcms:Title/)</a><span>(ylcms:Date/)</span>
</div>
<br />
{/ylcms}
</td>
<td align="left" valign="top" class="list">
<div class="list_title">国外大事<a href=''> 更多</a></div>
{ylcms:message type="11" number="20"}
<div>
国外大事<a href="(ylcms:Url/)">(ylcms:Title/)</a><span>(ylcms:Date/)</span>
</div>
<br />
{/ylcms}
</td>
</tr>
</table>
我想要输出的结果是包含:
{ylcms:pagetitle/}
{ylcms:message type="11"...}
.......
{/ylcms}
{ylcms:news type="11"...}
.......
{/ylcms}
请问可以再帮一下忙吗?
string str = File.ReadAllText(@"E:\1.txt", Encoding.GetEncoding("gb2312"));
Regex reg = new Regex(@"(?is)\{ylcms[^\}]+?\}(?:(?:(?!\{/?ylcms).)*{/ylcms\})?");
foreach (Match m in reg.Matches(str))
{
Console.WriteLine(m.Value);
Console.WriteLine(); Console.WriteLine(); Console.WriteLine(); Console.WriteLine();
}