可以使用正则表达式来移除一个字符串中的 HTML 代码。以下是一个示例代码:

using System.Text.RegularExpressions;

public static string RemoveHtmlTags(string html)
{
    // 移除所有 HTML 标签
    string pattern = @"<[^>]*>";
    string result = Regex.Replace(html, pattern, string.Empty);
    
    // 移除换行符和制表符
    result = result.Replace("\n", string.Empty);
    result = result.Replace("\r", string.Empty);
    result = result.Replace("\t", string.Empty);
    
    return result;
}

使用示例:

string html = "<p>This is <b>bold</b> text.</p>";
string text = RemoveHtmlTags(html);
Console.WriteLine(text); // 输出: "This is bold text."
``
c# 移除一个字符串中的html代码

原文地址: https://www.cveoy.top/t/topic/eCSX 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录