【发布时间】:2013-12-17 06:37:59
【问题描述】:
我有一个带有 html 代码的字符串。我想删除所有 html 标签。所以 之间的所有字符。
这是我截取的代码:
WebClient wClient = new WebClient();
SourceCode = wClient.DownloadString( txtSourceURL.Text );
txtSourceCode.Text = SourceCode;
//remove here all between "<" and ">"
txtSourceCodeFormatted.Text = SourceCode;
希望有人可以帮助我
【问题讨论】:
-
如果
<和>字符出现在 cmets、脚本、字符串等中怎么办? -
不,不要使用正则表达式来解析 HTML 字符串。一场真正的噩梦在等着你。这是 SO 中最受欢迎的答案之一。 stackoverflow.com/questions/1732348/… 最好的方法是使用专门的 HTML 解析器,例如 HTML Agility Pack
-
@Steve 我最喜欢的答案:)
-
在这种情况下使用 .NET XML-Parser 也可能有效?还是我错了?