這裏是我使用正則表達式的函數。它正在努力工作,但它的速度非常緩慢。 我認爲它是按字符搜索html代碼的字符。所以它的工作很慢。有沒有解決工作緩慢的問題。緩慢工作的原因和解決方案
string s = Sourcecode(richTextBox6.Text);
// <a ... > </a> tagları arasını alıyor.(taglar dahil)
Regex regex = new Regex("(?i)<a([^>]+)>(.+?)</a>");
string gelen = s;
string inside = null;
Match match = regex.Match(gelen);
if (match.Success)
{
inside= match.Value;
richTextBox2.Text = inside;
}
string outputStr = "";
foreach (Match ItemMatch in regex.Matches(gelen))
{
Console.WriteLine(ItemMatch);
inside = ItemMatch.Value;
//boşluk bırakıp al satır yazıyor
outputStr += inside + "\r\n";
}
richTextBox2.Text = outputStr;
請勿使用正則表達式。使用適當的HTML解析庫,如Html Agility Pack。你會看到速度提高了十倍。 –
任何不同的想法,爲什麼它採取標籤緩慢? – believeitornot
這可能會減慢它,如果有很多和很多要追加。 'outputStr + = inside +「\ r \ n」;' –