可以使用字符串的IndexOf方法来找到图片的起始位置,然后使用Substring方法截取出图片部分,最后将剩余的部分作为纯html处理。具体代码如下:

byte[] fileBytes = File.ReadAllBytes(filePath);
string html = Encoding.UTF8.GetString(fileBytes);

int imgStartIndex = html.IndexOf("<img");
if (imgStartIndex > 0)
{
    string pureHtml = html.Substring(0, imgStartIndex);
    // 处理纯html部分
    string imgPart = html.Substring(imgStartIndex);
    // 处理图片部分
}
else
{
    // 没有图片,处理全部html部分
}

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

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