zoukankan      html  css  js  c++  java
  • 正则表达式

                //匹配图片
                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;
                            }
                        }
                    }
                }

  • 相关阅读:
    Android 中退出程序的几种方法
    POJ 1860 Currency Exchange (Bellman-Ford)
    HDU 5183 Negative and Positive (NP) (手写哈希)
    C++ 常见的cin的错误处理
    POJ 2287 Tian Ji -- The Horse Racing (贪心)
    HDU 1205 吃糖果 (鸽巢原理)
    HDU 1028 Ignatius and the Princess III (动态规划)
    HDU 3746 Cyclic Nacklace (KMP找循环节)
    Codeforces Round #596 (Div. 2, based on Technocup 2020 Elimination Round 2)
    HDU 2087 剪花布条 (KMP)
  • 原文地址:https://www.cnblogs.com/EDSON/p/3357620.html
Copyright © 2011-2022 走看看