我有一个HTML代码的string。 我想删除所有的HTML标签。 所以<和>之间的所有字符。
这是我的代码剪断:
WebClient wClient = new WebClient(); SourceCode = wClient.DownloadString( txtSourceURL.Text ); txtSourceCode.Text = SourceCode; //remove here all between "<" and ">" txtSourceCodeFormatted.Text = SourceCode;
希望有人能帮助我
尝试这个:
txtSourceCodeFormatted.Text = Regex.Replace(SourceCode, "<.*?>", string.Empty);
但正如其他人所提到的, 谨慎处理 。
根据拉维的回答 ,你可以使用
string noHTML = Regex.Replace(inputHTML, @"<[^>]+>| ", "").Trim();
要么
string noHTMLNormalised = Regex.Replace(noHTML, @"\s{2,}", " ");