哈哈,你是不是也想
给你个参考
private void getLists(string roomid, string pageid)
{
this.listView1.BeginUpdate();
this.listView1.Items.Clear();
ListViewItem item1; string strUrl = "";
if (roomid.Length < 4)
{
strUrl = "http://community.csdn.net/Expert/ForumsList.asp?roomid=" + roomid + "&typenum=1&xmlsrc=/Expert/deeptree/Rooms/List.xml&csdnstyle=0&hidetoc=true&whichpage=" + pageid;
}
else
{
strUrl = "http://community.csdn.net/Expert/ForumList.asp?roomid=" + roomid + "&typenum=1&xmlsrc=/Expert/deeptree/Rooms/List.xml&csdnstyle=0&hidetoc=true&whichpage=" + pageid;
} this.richTextBox1.Clear();
this.richTextBox1.AppendText(strUrl + "\n\n");
//string strReg = @"TopicView1.asp\?id=(?<id>[\s]*?)""[^>]*>(?<text>[\s]*?)</a>";
//string strReg = @"TopicView1.asp\?id=(?<id>[\s\S]*?)""[^>]*>(?<text>[\s\S]*?)</a>";
string strReg = @"TopicView1.asp\?id=(?<id>[\s\S]*?)""[^>]*>(?<text>[\s\S]*?)</a>[^<]*</td>[^<]*<td[^>]*>(?<t1>[\s\S]*?)</td>" +
@"[^<]*<td[^>]*>(?<t2>[\s\S]*?)</td>[^<]*<td[^>]*>(?<t3>[\s\S]*?)</td>[^<]*<td[^>]*>(?<t4>[\s\S]*?)</td>";
string getstr = "";
int i = 0;
string str = RDA.getIDLists(strUrl);
//this.richTextBox1.AppendText(str + "\r\n \r\n \r\n \r\n ");
Regex r = new Regex(strReg, RegexOptions.Compiled);
for (Match m = r.Match(str); m.Success; m = m.NextMatch())
{
i++;
this.richTextBox1.AppendText(i.ToString() + " ----------------------------------------------------------------------------------\r\n");
getstr = m.Result("${id}");
item1 = new ListViewItem(getstr, 0);
this.richTextBox1.AppendText(getstr + "\r\n");
getstr = m.Result("${text}");
item1.SubItems.Add(getstr);
this.richTextBox1.AppendText(getstr + "\r\n");
getstr = m.Result("${t1}");
item1.SubItems.Add(getstr);
this.richTextBox1.AppendText(getstr + "\r\n");
getstr = m.Result("${t2}");
item1.SubItems.Add(getstr);
this.richTextBox1.AppendText(getstr + "\r\n");
getstr = m.Result("${t3}");
item1.SubItems.Add(getstr);
this.richTextBox1.AppendText(getstr + "\r\n");
getstr = m.Result("${t4}");
item1.SubItems.Add(getstr);
this.richTextBox1.AppendText(getstr + "\r\n");
listView1.Items.Add(item1);
}
this.listView1.EndUpdate(); this.richTextBox1.AppendText("\r\n\r\n");
this.richTextBox1.AppendText(str);
}
给你个参考
private void getLists(string roomid, string pageid)
{
this.listView1.BeginUpdate();
this.listView1.Items.Clear();
ListViewItem item1; string strUrl = "";
if (roomid.Length < 4)
{
strUrl = "http://community.csdn.net/Expert/ForumsList.asp?roomid=" + roomid + "&typenum=1&xmlsrc=/Expert/deeptree/Rooms/List.xml&csdnstyle=0&hidetoc=true&whichpage=" + pageid;
}
else
{
strUrl = "http://community.csdn.net/Expert/ForumList.asp?roomid=" + roomid + "&typenum=1&xmlsrc=/Expert/deeptree/Rooms/List.xml&csdnstyle=0&hidetoc=true&whichpage=" + pageid;
} this.richTextBox1.Clear();
this.richTextBox1.AppendText(strUrl + "\n\n");
//string strReg = @"TopicView1.asp\?id=(?<id>[\s]*?)""[^>]*>(?<text>[\s]*?)</a>";
//string strReg = @"TopicView1.asp\?id=(?<id>[\s\S]*?)""[^>]*>(?<text>[\s\S]*?)</a>";
string strReg = @"TopicView1.asp\?id=(?<id>[\s\S]*?)""[^>]*>(?<text>[\s\S]*?)</a>[^<]*</td>[^<]*<td[^>]*>(?<t1>[\s\S]*?)</td>" +
@"[^<]*<td[^>]*>(?<t2>[\s\S]*?)</td>[^<]*<td[^>]*>(?<t3>[\s\S]*?)</td>[^<]*<td[^>]*>(?<t4>[\s\S]*?)</td>";
string getstr = "";
int i = 0;
string str = RDA.getIDLists(strUrl);
//this.richTextBox1.AppendText(str + "\r\n \r\n \r\n \r\n ");
Regex r = new Regex(strReg, RegexOptions.Compiled);
for (Match m = r.Match(str); m.Success; m = m.NextMatch())
{
i++;
this.richTextBox1.AppendText(i.ToString() + " ----------------------------------------------------------------------------------\r\n");
getstr = m.Result("${id}");
item1 = new ListViewItem(getstr, 0);
this.richTextBox1.AppendText(getstr + "\r\n");
getstr = m.Result("${text}");
item1.SubItems.Add(getstr);
this.richTextBox1.AppendText(getstr + "\r\n");
getstr = m.Result("${t1}");
item1.SubItems.Add(getstr);
this.richTextBox1.AppendText(getstr + "\r\n");
getstr = m.Result("${t2}");
item1.SubItems.Add(getstr);
this.richTextBox1.AppendText(getstr + "\r\n");
getstr = m.Result("${t3}");
item1.SubItems.Add(getstr);
this.richTextBox1.AppendText(getstr + "\r\n");
getstr = m.Result("${t4}");
item1.SubItems.Add(getstr);
this.richTextBox1.AppendText(getstr + "\r\n");
listView1.Items.Add(item1);
}
this.listView1.EndUpdate(); this.richTextBox1.AppendText("\r\n\r\n");
this.richTextBox1.AppendText(str);
}
解决方案 »
- 条码打印问题。。。急!!
- 如何实现PropertyGrid的缩放功能?
- c# hook api的问题~~~
- 那位能发一个Windows ce 上 sqlce 操作的例子
- VB.net里写的一个函数用了optional属性的参数,在C#里为什么这个默认值非填不可?
- 请问如何将一个窗口置于另一个窗口之上
- LanMSg 聊天工具 怎么使用? 谁有使用说明的?
- 我应该的用什么类型的变量接它
- 一种类似树状的传销算法,求助~~~~~~~~~~~~~
- 简单问题,在线急等!!
- 请问如何通过进程句柄或进程ID或线程ID来获得程序的主窗体?
- 本人正尝试做一自定义webcontrol,用于显示一个界面,不知怎样render?
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim xml As String = "<table> ... </table>" '*** 调整没有用双引号括起来的属性
Dim pattern As String = "=(?<value>[^""]\w*)"
Dim replacement As String = "=""${value}"""
Dim r As New System.Text.RegularExpressions.Regex(pattern)
xml = r.Replace(xml, replacement) '*** 将所有标记替换为大写
pattern="<(?<>/)*(?<name>\S+)"
xml = r.Replace(xml, pattern, _
New System.Text.RegularExpressions.MatchEvaluator(AddressOf Me.MatchEvaluator)) '*** 读取这个XML
Dim doc As New XmlDocument
doc.LoadXml(xml) Dim table As XmlNode = doc.FirstChild
Me.DisplayNode(table, 0)
End Sub'*** 执行替换的函数
Private Function MatchEvaluator(ByVal m As System.Text.RegularExpressions.Match) As String
Return m.Value.ToUpper
End Function'*** 显示XMLNODE的所有属性,并通过递归显示其下的子NODE
Private Sub DisplayNode(ByVal Node As XmlNode, ByVal Level As Integer)
Dim s As String = New String(" "c, Level << 2)
If TypeOf Node Is XmlText Then
Debug.WriteLine(Node.Value)
Else
Debug.WriteLine(Node.Name)
End If
If Not Node.Attributes Is Nothing Then
For Each a As XmlAttribute In Node.Attributes
Debug.WriteLine(s & a.Name & "=" & a.Value)
Next
End If
If Node.ChildNodes.Count > 0 Then
For Each n As XmlNode In Node.ChildNodes
Me.DisplayNode(n, Level + 1)
Next
End If
End Sub以上不一定是个好方法,是在看你的帖子时忽然想到的,觉得挺有趣,就写出来了,希望能对你有帮助。
Sunmast(速马|ALL STAR) 的方法好
using System.IO;
using System.Text.RegularExpressions;class TestReg2
{
static void Main(string[] args)
{
string s = "........";
Regex re = new Regex(@"<TD width=""14%""><FONT color=#631842>(?<content>[^<>]+)</FONT></TD>", RegexOptions.IgnoreCase);
foreach (Match m in re.Matches(s))
Console.WriteLine(m.Groups["content"].Value);
}
}if you want more flexibility, you could try
using System;
using System.IO;
using System.Text.RegularExpressions;class TestReg2
{
static void Main(string[] args)
{
string s = "........";
Regex re = new Regex(@"<table[^>]*>\s*<tr[^>]*>(\s*<TD[^>]*><FONT[^>]+>(?<content>[^<>]+)</FONT></TD>)*\s*</tr>\s*</table>", RegexOptions.IgnoreCase);
Match m = re.Match(s);
if (m.Success)
{
foreach (Capture c in m.Groups["content"].Captures)
Console.WriteLine(c.Value);
} }
}
Dim sr As StreamReader = New StreamReader(ss, System.Text.Encoding.Default)
Try
Dim line As String
Do
line = sr.ReadLine()
Dim i As Integer
If line.Length > 27 Then
For i = 1 To line.Length
Dim str As String
Try
If Mid(line, i, 7) = "631842>" Then
Dim j As Integer
For j = i + 7 To line.Length
If Mid(line, j, 1) = "<" Then
Exit For
End If
str = str & Mid(line, j, 1)
Next
Label1.Text = str
Exit For
End If
Catch ex As Exception
Exit For
End Try
Next
End If
Loop Until line Is Nothing
sr.Close()
Return "ok"
Catch ex As Exception
Return "err"
End Try
End Function