有这么一个字符串:
想取得 bgColor=#fdfcf8><A
href=" 和 "> 之间的字符!
注意我这个字符串 可能包含很多这样的字符! 我都要一一取得! 请问大家有什么好的办法!
<TD align=middle width=7 bgColor=#fdfcf8><IMG height=5
src="分类信息.files/qian.gif" width=5></TD>
<TD class=unnamed1 align=middle width=152
bgColor=#fdfcf8><A
href="http://classad.zbinfo.net/classfb2.asp?classid=160&parentclassid=14">
<DIV align=center>[手 机]</DIV></A>
<TD class=unnamed1 align=left width=630
bgColor=#fdfcf8><A
href="http://classad.zbinfo.net/classfb3.asp?ad_id=86066">韩国机卡一体CDMA手机最新报价!刚到新货欲购从速/有图
</A><IMG src="分类信息.files/160.gif"></TD>
<TD class=unnamed1 align=middle width=149
bgColor=#fdfcf8><DIV align=center>05-11-19</DIV></TD>
<TD class=unnamed1 align=middle width=39
bgColor=#fdfcf8><DIV align=center></DIV></TD></TR>
<TR>
<TD align=middle width=7 bgColor=#fdfcf8><IMG height=5
src="分类信息.files/qian.gif" width=5></TD>
<TD class=unnamed1 align=middle width=152
bgColor=#fdfcf8><A
href="http://classad.zbinfo.net/classfb2.asp?classid=160&parentclassid=14">
<DIV align=center>[手 机]</DIV></A>
<TD class=unnamed1 align=left width=630
bgColor=#fdfcf8><A
href="http://classad.zbinfo.net/classfb3.asp?ad_id=82836">办理交30打150话费的手机卡,交50打200的双模手机卡
</A><IMG src="分类信息.files/160.gif"></TD>
<TD class=unnamed1 align=middle width=149
bgColor=#fdfcf8><DIV align=center>05-11-19</DIV></TD>
<TD class=unnamed1 align=middle width=39
bgColor=#fdfcf8><DIV align=center></DIV></TD></TR>
<TR>
<TD align=middle width=7 bgColor=#fdfcf8><IMG height=5
src="分类信息.files/qian.gif" width=5></TD>
<TD class=unnamed1 align=middle width=152
bgColor=#fdfcf8><A
href="http://classad.zbinfo.net/classfb2.asp?classid=160&parentclassid=14">
<DIV align=center>[手 机]</DIV></A>
<TD class=unnamed1 align=left width=630
bgColor=#fdfcf8><A
href="http://classad.zbinfo.net/classfb3.asp?ad_id=85977">开公车的朋友来看看;;;;;;;;;;;;;;;;;;;;;
</A><IMG src="分类信息.files/160.gif"></TD>
<TD class=unnamed1 align=middle width=149
bgColor=#fdfcf8><DIV align=center>05-11-19</DIV></TD>
<TD class=unnamed1 align=middle width=39
bgColor=#fdfcf8><DIV align=center></DIV></TD></TR>
<TR>
<TD align=middle width=7 bgColor=#fdfcf8><IMG height=5
src="分类信息.files/qian.gif" width=5></TD>
<TD class=unnamed1 align=middle width=152
bgColor=#fdfcf8><A
href="http://classad.zbinfo.net/classfb2.asp?classid=160&parentclassid=14">
<DIV align=center>[手 机]</DIV></A>
<TD class=unnamed1 align=left width=630
bgColor=#fdfcf8><A
href="http://classad.zbinfo.net/classfb3.asp?ad_id=85975">卡卡卡卡卡卡卡卡卡卡卡卡卡卡卡卡
</A><IMG src="分类信息.files/160.gif"></TD>
<TD class=unnamed1 align=middle width=149
bgColor=#fdfcf8><DIV align=center>05-11-19</DIV></TD>
<TD class=unnamed1 align=middle width=39
bgColor=#fdfcf8><DIV align=center></DIV></TD></TR>
<TR>
<TD align=middle width=7 bgColor=#fdfcf8><IMG height=5
src="分类信息.files/qian.gif" width=5></TD>
<TD class=unnamed1 align=middle width=152
bgColor=#fdfcf8><A
href="http://classad.zbinfo.net/classfb2.asp?classid=160&parentclassid=14">
<DIV align=center>[手 机]</DIV></A>
<TD class=unnamed1 align=left width=630
bgColor=#fdfcf8><A
href="http://classad.zbinfo.net/classfb3.asp?ad_id=86053">转让自用发发卡
</A></TD>
<TD class=unnamed1 align=middle width=149
bgColor=#fdfcf8><DIV align=center>05-11-19</DIV></TD>
<TD class=unnamed1 align=middle width=39
bgColor=#fdfcf8><DIV align=center></DIV></TD></TR>
<TR>
<TD align=middle width=7 bgColor=#fdfcf8><IMG height=5
src="分类信息.files/qian.gif" width=5></TD>
<TD class=unnamed1 align=middle width=152
bgColor=#fdfcf8><A
href="http://classad.zbinfo.net/classfb2.asp?classid=160&parentclassid=14">
<DIV align=center>[手 机]</DIV></A>
<TD class=unnamed1 align=left width=630
bgColor=#fdfcf8><A
href="http://classad.zbinfo.net/classfb3.asp?ad_id=85704">转让小灵通靓号8061999
</A></TD>
<TD class=unnamed1 align=middle width=149
bgColor=#fdfcf8><DIV align=center>05-11-19</DIV></TD>
<TD class=unnamed1 align=middle width=39
bgColor=#fdfcf8><DIV align=center></DIV></TD></TR>
<TR>
<TD align=middle width=7 bgColor=#fdfcf8><IMG height=5
src="分类信息.files/qian.gif" width=5></TD>
<TD class=unnamed1 align=middle width=152
bgColor=#fdfcf8><A
href="http://classad.zbinfo.net/classfb2.asp?classid=160&parentclassid=14">
<DIV align=center>[手 机]</DIV></A>
<TD class=unnamed1 align=left width=630
bgColor=#fdfcf8><A
href="http://classad.zbinfo.net/classfb3.asp?ad_id=85708">买cd机
快快快 </A></TD>
想取得 bgColor=#fdfcf8><A
href=" 和 "> 之间的字符!
注意我这个字符串 可能包含很多这样的字符! 我都要一一取得! 请问大家有什么好的办法!
<TD align=middle width=7 bgColor=#fdfcf8><IMG height=5
src="分类信息.files/qian.gif" width=5></TD>
<TD class=unnamed1 align=middle width=152
bgColor=#fdfcf8><A
href="http://classad.zbinfo.net/classfb2.asp?classid=160&parentclassid=14">
<DIV align=center>[手 机]</DIV></A>
<TD class=unnamed1 align=left width=630
bgColor=#fdfcf8><A
href="http://classad.zbinfo.net/classfb3.asp?ad_id=86066">韩国机卡一体CDMA手机最新报价!刚到新货欲购从速/有图
</A><IMG src="分类信息.files/160.gif"></TD>
<TD class=unnamed1 align=middle width=149
bgColor=#fdfcf8><DIV align=center>05-11-19</DIV></TD>
<TD class=unnamed1 align=middle width=39
bgColor=#fdfcf8><DIV align=center></DIV></TD></TR>
<TR>
<TD align=middle width=7 bgColor=#fdfcf8><IMG height=5
src="分类信息.files/qian.gif" width=5></TD>
<TD class=unnamed1 align=middle width=152
bgColor=#fdfcf8><A
href="http://classad.zbinfo.net/classfb2.asp?classid=160&parentclassid=14">
<DIV align=center>[手 机]</DIV></A>
<TD class=unnamed1 align=left width=630
bgColor=#fdfcf8><A
href="http://classad.zbinfo.net/classfb3.asp?ad_id=82836">办理交30打150话费的手机卡,交50打200的双模手机卡
</A><IMG src="分类信息.files/160.gif"></TD>
<TD class=unnamed1 align=middle width=149
bgColor=#fdfcf8><DIV align=center>05-11-19</DIV></TD>
<TD class=unnamed1 align=middle width=39
bgColor=#fdfcf8><DIV align=center></DIV></TD></TR>
<TR>
<TD align=middle width=7 bgColor=#fdfcf8><IMG height=5
src="分类信息.files/qian.gif" width=5></TD>
<TD class=unnamed1 align=middle width=152
bgColor=#fdfcf8><A
href="http://classad.zbinfo.net/classfb2.asp?classid=160&parentclassid=14">
<DIV align=center>[手 机]</DIV></A>
<TD class=unnamed1 align=left width=630
bgColor=#fdfcf8><A
href="http://classad.zbinfo.net/classfb3.asp?ad_id=85977">开公车的朋友来看看;;;;;;;;;;;;;;;;;;;;;
</A><IMG src="分类信息.files/160.gif"></TD>
<TD class=unnamed1 align=middle width=149
bgColor=#fdfcf8><DIV align=center>05-11-19</DIV></TD>
<TD class=unnamed1 align=middle width=39
bgColor=#fdfcf8><DIV align=center></DIV></TD></TR>
<TR>
<TD align=middle width=7 bgColor=#fdfcf8><IMG height=5
src="分类信息.files/qian.gif" width=5></TD>
<TD class=unnamed1 align=middle width=152
bgColor=#fdfcf8><A
href="http://classad.zbinfo.net/classfb2.asp?classid=160&parentclassid=14">
<DIV align=center>[手 机]</DIV></A>
<TD class=unnamed1 align=left width=630
bgColor=#fdfcf8><A
href="http://classad.zbinfo.net/classfb3.asp?ad_id=85975">卡卡卡卡卡卡卡卡卡卡卡卡卡卡卡卡
</A><IMG src="分类信息.files/160.gif"></TD>
<TD class=unnamed1 align=middle width=149
bgColor=#fdfcf8><DIV align=center>05-11-19</DIV></TD>
<TD class=unnamed1 align=middle width=39
bgColor=#fdfcf8><DIV align=center></DIV></TD></TR>
<TR>
<TD align=middle width=7 bgColor=#fdfcf8><IMG height=5
src="分类信息.files/qian.gif" width=5></TD>
<TD class=unnamed1 align=middle width=152
bgColor=#fdfcf8><A
href="http://classad.zbinfo.net/classfb2.asp?classid=160&parentclassid=14">
<DIV align=center>[手 机]</DIV></A>
<TD class=unnamed1 align=left width=630
bgColor=#fdfcf8><A
href="http://classad.zbinfo.net/classfb3.asp?ad_id=86053">转让自用发发卡
</A></TD>
<TD class=unnamed1 align=middle width=149
bgColor=#fdfcf8><DIV align=center>05-11-19</DIV></TD>
<TD class=unnamed1 align=middle width=39
bgColor=#fdfcf8><DIV align=center></DIV></TD></TR>
<TR>
<TD align=middle width=7 bgColor=#fdfcf8><IMG height=5
src="分类信息.files/qian.gif" width=5></TD>
<TD class=unnamed1 align=middle width=152
bgColor=#fdfcf8><A
href="http://classad.zbinfo.net/classfb2.asp?classid=160&parentclassid=14">
<DIV align=center>[手 机]</DIV></A>
<TD class=unnamed1 align=left width=630
bgColor=#fdfcf8><A
href="http://classad.zbinfo.net/classfb3.asp?ad_id=85704">转让小灵通靓号8061999
</A></TD>
<TD class=unnamed1 align=middle width=149
bgColor=#fdfcf8><DIV align=center>05-11-19</DIV></TD>
<TD class=unnamed1 align=middle width=39
bgColor=#fdfcf8><DIV align=center></DIV></TD></TR>
<TR>
<TD align=middle width=7 bgColor=#fdfcf8><IMG height=5
src="分类信息.files/qian.gif" width=5></TD>
<TD class=unnamed1 align=middle width=152
bgColor=#fdfcf8><A
href="http://classad.zbinfo.net/classfb2.asp?classid=160&parentclassid=14">
<DIV align=center>[手 机]</DIV></A>
<TD class=unnamed1 align=left width=630
bgColor=#fdfcf8><A
href="http://classad.zbinfo.net/classfb3.asp?ad_id=85708">买cd机
快快快 </A></TD>
CSDN小助手是一款脱离浏览器也可以访问Csdn论坛的软件
界面:http://blog.csdn.net/Qqwwee_Com/archive/2005/11/05/523395.aspx
下载:http://szlawbook.com/csdnv2
using System.Text.RegularExpressions;namespace GetLinks
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
class Class1
{
private const string HTML = @"
<TD align=middle width=7 bgColor=#fdfcf8><IMG height=5
src=""分类信息.files/qian.gif"" width=5></TD>
<TD class=unnamed1 align=middle width=152
bgColor=#fdfcf8><A
href=""http://classad.zbinfo.net/classfb2.asp?classid=160&parentclassid=14"">
<DIV align=center>[手 机]</DIV></A> ....... <TD class=unnamed1 align=left width=630
bgColor=#fdfcf8><A
href=""http://classad.zbinfo.net/classfb3.asp?ad_id=85708"">买cd机
快快快 </A></TD>
"; /// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{
Console.WriteLine("提取到的链接:");
Console.WriteLine(String.Join("\r\n", ExtractLinks(HTML)));
Console.ReadLine();
} static string[] ExtractLinks(string html)
{
Regex re = new Regex(@"bgColor=#fdfcf8><A\s+href=""([^""]+)"">");
MatchCollection mc = re.Matches(html);
string[] output = new string[mc.Count];
int i = 0;
foreach (Match match in mc)
output[i++] = match.Groups[1].Value;
return output;
}
}
}
我不想使用正则
因为我的那个 bgColor=#fdfcf8><A
href=" 和 "> 我想自定义的输入====CSDN 小助手 V2.5 2005年11月05日发布====
CSDN小助手是一款脱离浏览器也可以访问Csdn论坛的软件
界面:http://blog.csdn.net/Qqwwee_Com/archive/2005/11/05/523395.aspx
下载:http://szlawbook.com/csdnv2
{
Console.WriteLine("提取到的链接:");
Console.WriteLine(String.Join("\r\n", ExtractLinks(HTML,
"bgColor=#fdfcf8><A \r\n href=\"", "\">")));
Console.ReadLine();
} static string[] ExtractLinks(string html, string beforeText, string afterText)
{
System.Collections.ArrayList list = new System.Collections.ArrayList();
int pos1 = 0, pos2 = 0;
while ((pos1 = html.IndexOf(beforeText, pos2)) != -1)
{
pos1 += beforeText.Length;
if ((pos2 = html.IndexOf(afterText, pos1)) == -1)
break;
list.Add(html.Substring(pos1, pos2 - pos1));
}
return (string[])list.ToArray(typeof(string));
}