• 正则表达式


                //匹配图片
                var regexImg = new Regex(@"<img (.*?)src=(.[^[^>]*)(.*?)>", RegexOptions.IgnoreCase);
                var matches = regexImg.Matches(editor1.BodyHtml);
                var ftp = Common.NewsFtp(true);
                //遍历每个图片
                foreach (Match match in matches)
                {
                    string localPath = match.Value;
                    //匹配地址
                    var regex = new Regex("src="(.*)">");
                    var matchLocal = regex.Match(localPath);
                    if (matchLocal.Success)
                    {
                        string str = matchLocal.Groups[1].Value;
                        if (File.Exists(str))
                        {
                            var fileInfo = new FileInfo(str);
                            string dir = Path.GetDirectoryName(str);
                            string ext = Path.GetExtension(str);
                            string path = dir + "\" + Guid.NewGuid() + ext;
                            fileInfo.MoveTo(path);
                            try
                            {
                                ftp.UploadFile(path, "");
                                string s = BasePath.ContentImagesAbsoluteURI +
                                           Path.GetFileName(path);
                                string detail = t.NewsDetail;
                                detail = detail.Replace(str, s);
                                t.NewsDetail = detail;
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show(ex.Message);
                                return;
                            }
                        }
                    }
                }

  • 相关阅读:
    5年多了
    处女作
    2.2 Multinomial variables多项变量的分布_PRML模式识别与机器学习读书笔记
    2.1 Binary variables 二元变量分布_PRML模式识别与机器学习读书笔记
    1.1 Example:Polynomial Curve Fitting 多项式曲线拟合_PRML模式识别与机器学习读书笔记
    1 Introduction_PRML模式识别与机器学习读书笔记
    操作系统概述
    TFS2015创建项目
    PowerDesigner
    python实用函数
  • 原文地址:https://www.cnblogs.com/EDSON/p/3357620.html
Copyright © 2020-2023  润新知