获取表格中的值

xutaohappy123456 2011-09-01 01:13:13
<div id="table_body">
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="tab02">
<tr class="trbg" onmouseover="this.className='caing_hover'" onmouseout="this.className='trbg'">
<td width="25%">11年7月</td>
<td width="25%">45,183.07</td>
<td width="25%">270,558.64</td>
<td width="25%">772,937.56</td>
</tr>

<tr onmouseover="this.className='caing_hover'" onmouseout="this.className=''">
<td width="25%">11年6月</td>
<td width="25%">44,477.80</td>
<td width="25%">274,662.57</td>
<td width="25%">780,820.85</td>
</tr>

<tr class="trbg" onmouseover="this.className='caing_hover'" onmouseout="this.className='trbg'">
<td width="25%">11年5月</td>
<td width="25%">44,602.83</td>
<td width="25%">269,289.63</td>
<td width="25%">763,409.22</td>
</tr>

<tr onmouseover="this.className='caing_hover'" onmouseout="this.className=''">
<td width="25%">11年4月</td><td width="25%">45,489.03</td>
<td width="25%">266,766.91</td>
<td width="25%">757,384.56</td>
</tr>
</table>
</div>

我想获取<td></td>间的值,不知怎么获取,请大家指点一二?
...全文
63 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
weboscar 2011-09-01
  • 打赏
  • 举报
回复
这是你要的~在你的Form1放一个 RichTextBox 试试吧


string yourStr = @" <div id='table_body'>
<table width='100%' border='0' cellspacing='0' cellpadding='0' class='tab02'>
<tr class='trbg' onmouseover='this.className='caing_hover'' onmouseout='this.className='trbg''>
<td width='25%'>11年7月</td>
<td width='25%'>45,183.07</td>
<td width='25%'>270,558.64</td>
<td width='25%'>772,937.56</td>
</tr>
<tr onmouseover='this.className='caing_hover'' onmouseout='this.className='''>
<td width='25%'>11年6月</td>
<td width='25%'>44,477.80</td>
<td width='25%'>274,662.57</td>
<td width='25%'>780,820.85</td>
</tr>
<tr class='trbg' onmouseover='this.className='caing_hover'' onmouseout='this.className='trbg''>
<td width='25%'>11年5月</td>
<td width='25%'>44,602.83</td>
<td width='25%'>269,289.63</td>
<td width='25%'>763,409.22</td>
</tr>
<tr onmouseover='this.className='caing_hover'' onmouseout='this.className='''>
<td width='25%'>11年4月</td><td width='25%'>45,489.03</td>
<td width='25%'>266,766.91</td>
<td width='25%'>757,384.56</td>
</tr>
</table>
</div>";

System.Text.RegularExpressions.MatchCollection mc = System.Text.RegularExpressions.Regex.Matches(yourStr, @"(?is)(?<=<td[^>]*>)(?!\s*</td)(?:(?!</td\b).)*(?=</td>)");
foreach (System.Text.RegularExpressions.Match m in mc)
{
string temp = System.Text.RegularExpressions.Regex.Replace(m.Value, @"<[^>]*>|\s+", "");
if (temp != "")
richTextBox1.Text += temp + "\n";
}
xutaohappy123456 2011-09-01
  • 打赏
  • 举报
回复
我初次接触,能具体点嘛,给个例子
stonespace 2011-09-01
  • 打赏
  • 举报
回复
用正则表达式分析,

110,502

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧