从文本中删除锚标记

本文关键字:删除 文本 | 更新日期: 2023-09-27 18:02:27

如何从字符串中删除锚标记,我有一个大的文本,有些词有锚标记,我想删除该锚标记,并希望显示普通的词(没有锚标记)。我的文本看起来像:

LoremIpsum。Net是一个小而简单的静态站点为您提供了一个体面的大小的段落,而不必使用发电机。该网站还提供了一个全大写版本的文本,如以及翻译,并解释什么是著名的。

从文本中删除锚标记

如果您想要一个非常简单(且非防弹)的示例,请参见下面的示例。但是,我仍然强烈建议您找到一个"合适的"html解析器。

using System;
using System.Text.RegularExpressions;
public class Test
{
        public static void Main()
        {
                String sample = "<a href='"http://test.com'" rel='"nofollow'">LoremIpsum.Net</a> is a small and simple static site that <a href='"http://test123.com'" rel='"nofollow'">provides</a> you with a decent sized passage without having to use a generator. The site also provides an all caps version of the text, as well as translations, and an <a href='"http://test445.com'" rel='"nofollow'">explanation</a> of what this famous.";
                String re = @"<a [^>]+>(.*?)<'/a>";
                Console.WriteLine(Regex.Replace(sample, re, "$1"));
        }
}

LoremIpsum。Net是一个小而简单的静态站点,它为您提供了一个体面的大小的通道,而无需使用生成器。该网站还提供了一个全大写版本的文本,以及翻译,并解释了这个著名的。

下面是我剥离Html的代码:

public static string StripHTML(this string HTMLText)
{
    var reg = new Regex("<[^>]+>", RegexOptions.IgnoreCase);
    return reg.Replace(HTMLText, "").Replace("&nbsp;", " ");
}

很好的例子:

http://www.dotnetperls.com/remove-html-tags