/// <summary> /// 时间:2018年7月18日09:04:18 /// 说明:清理Html标签 /// 作者:成建军 /// </summary> /// <param name="html"></param> /// <returns></returns> public static string ClearHtml(string html) { try { if (string.IsNullOrEmpty(html)) return html; while (html.IndexOf("<") >= 0) { var startIndex = html.IndexOf("<"); var endIndex = html.IndexOf(">") + 1; if (endIndex > startIndex) html = html.Remove(startIndex, endIndex - startIndex); } } catch (Exception) { return html; } return html; }
本文介绍了一个用于清理HTML标签的C#方法,通过遍历字符串并移除所有HTML标签,确保纯文本内容的干净输出。该方法适用于需要从HTML源中提取纯文本的应用场景。
4万+

被折叠的 条评论
为什么被折叠?



