#region 获取字符串中img的url集合
/// <summary>
/// 获取字符串中img的url集合
/// </summary>
/// <param name="content">字符串</param>
/// <returns>返回结果的url集合</returns>
public static List<string> getImgUrl(string content)
{
Regex rg = new Regex("src=\"([^\"]+)\"", RegexOptions.IgnoreCase);
var m = rg.Match(content);
List<string> imgUrl = new List<string>();
while (m.Success)
{
imgUrl.Add(m.Groups[1].Value); //这里就是图片路径
m = m.NextMatch();
}
return imgUrl;
}
#endregion
/// <summary>
/// 获取字符串中img的url集合
/// </summary>
/// <param name="content">字符串</param>
/// <returns>返回结果的url集合</returns>
public static List<string> getImgUrl(string content)
{
Regex rg = new Regex("src=\"([^\"]+)\"", RegexOptions.IgnoreCase);
var m = rg.Match(content);
List<string> imgUrl = new List<string>();
while (m.Success)
{
imgUrl.Add(m.Groups[1].Value); //这里就是图片路径
m = m.NextMatch();
}
return imgUrl;
}
#endregion
本文介绍了一种使用正则表达式从HTML字符串中提取所有img标签内的图片URL的方法,并提供了一个具体的C#实现示例。
1924

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



