/// <summary> /// 文本编辑器中添加的非网络图片,添加图片前缀URL /// </summary> /// <param name="strContent"></param> /// <returns></returns> public string addNativePicUrl(string strContent) { if (!string.IsNullOrEmpty(strContent)) { Regex regImg = new Regex(@"<img\b[^<>]*?\bsrc[\s\t\r\n]*=[\s\t\r\n]*[""']?[\s\t\r\n]*(?<imgUrl>[^\s\t\r\n""'<>]*)[^<>]*?/?[\s\t\r\n]*>", RegexOptions.IgnoreCase); MatchCollection matches = regImg.Matches(strContent); int i = 0; string[] sUrlList = new string[matches.Count]; if (matches.Count > 0) { // 取得匹配项列表 foreach (Match match in matches) { sUrlList[i++] = match.Groups["imgUrl"].Value; } string strAllEndUrl = strContent; for (int iCount = 0; iCount < sUrlList.Length; iCount++) { string strPicUrl = sUrlList[iCount].ToString(); if (!strPicUrl.Contains("http://")) { string strEndUrl = _domain + strPicUrl;//链接 string strReplaceText = strAllEndUrl.Replace(strPicUrl, strEndUrl); strAllEndUrl = strReplaceText; } } return strAllEndUrl; } else { return strContent; } } else { return strContent; } }
版权声明:本站资源除特殊标注外均收集自网络或由用户发布,如有侵权请联系删除。
还木有评论哦,快来抢沙发吧~