【问题标题】:I replace the base 64 image with url我用 url 替换 base 64 图像
【发布时间】:2020-11-26 15:49:23
【问题描述】:

我有一个包含 HTML 和 base 64 图像的字符串,我使用 Regax 分隔图像并上传它,我有一个文件路径需要在图像标签中替换才能返回。

这是我分离 base 64 图像的地方:

    var base64image = Regex.Match(request.Note, "(?<=data:image/jpeg;base64,)[^\"]*");

这是我替换它的地方。

  request.Note = request.Note.Replace(base64image.Value, url);

"<p>This is test </p><p><img src=\"data:image/jpeg;base64,https://files.test.com/qa/test.jpg\"></p>"

我有这个额外的:this:data:image/jpeg;base64,替换它的最佳方法是什么?

【问题讨论】:

    标签: c#


    【解决方案1】:

    您可以使用正则表达式Match.Groups Property

    像这样的

    var htmlImageMatches = Regex.Match(request.Note, "(data:image/jpeg;base64,)([^\"]*)");
    
    var discardText = htmlImageMatches.Groups[1];
    var base64image = htmlImageMatches.Groups[2];
    
    request.Note = request.Note.Replace(base64image.Value, url);
    request.Note = request.Note.Replace(discardText, "");
    

    【讨论】:

      猜你喜欢
      • 2017-08-28
      • 1970-01-01
      • 2017-10-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-23
      相关资源
      最近更新 更多