如何在c#
中获取bbcode文本中的第一个图像墨水我将此代码用于html,但如何为bbcode
执行此操作HtmlDocument document = new HtmlDocument();
document.LoadHtml(Model.TextSujet);
var imageUrl = (from image in document.DocumentNode.Descendants("img")
where !String.IsNullOrEmpty(image.GetAttributeValue("src", null))
select image.Attributes["src"].Value).FirstOrDefault();
答案 0 :(得分:0)
我建议使用正则表达式
var regex = new System.Text.RegularExpressions.Regex(@"\[img[^\]]*\]([^\[]*)");
string text = @"Including an image
[img]http://www.bbcode.org/images/lubeck_small.jpg[/img]
Resizing the image
[img=100x50]http://www.bbcode.org/images/lubeck_small.jpg[/img]
Making the image clickable (in this case linking to the original image)
[url=http://www.bbcode.org/images/lubeck.jpg][img]http://www.bbcode.org/images/lubeck_small.jpg[/img][/url]
Resizing and adding meta information for the image";
var match = regex.Match(text);
if (match.Success)
{
Console.WriteLine(match.Groups[1]);
}