作者heliosy (这一栏是要做啥用的)
看板C_Sharp
标题[问题] 用Regex去消除html的hyperlink
时间Wed Aug 24 16:46:40 2005
以下是我试写的简单程式码
Regex re = new Regex("<a href=.*\">");
StreamReader sr = new StreamReader("a.htm");
string line = null;
string all = null;
while((line = sr.ReadLine()) != null)
{
if(line.IndexOf("<a href=") != -1)
{
all += re.Replace(line,"").Replace("</a>","") + "\r\n";
}
else
{
all += line + "\r\n";
}
}
sr.Close();
StreamWriter sw = new StreamWriter("b.htm");
sw.Write(all);
sw.Flush();
sw.Close();
但是这样如果遇到一行中有两个hyperlink的话
就会把第一个hyperlink全都删掉了
有什麽判断方式可以让他遇到第一个</a>就停止,然後再继续判断下一个吗
谢谢
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.109.42.171