【问题标题】:Get First Img link in bbcode C#在 bbcode C# 中获取第一个 Img 链接
【发布时间】:2014-12-28 16:52:04
【问题描述】:

如何在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();

【问题讨论】:

  • 对不起,我没有正确阅读问题,感谢您指出@codemonkey

标签: c# asp.net-mvc entity-framework bbcode


【解决方案1】:

我建议使用正则表达式

        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]);
        }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-09-12
    • 1970-01-01
    • 1970-01-01
    • 2012-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多