zoukankan      html  css  js  c++  java
  • 【Vegas原创】用正则表达式解决FCKEditor图片路径问题

    在用FCKEditor发邮件时,正文中图片会显示不出来,因为它默认路径是userfiles/images/*.jpg,如下

    <input type="image" height="131" width="139" 

    src="/userfiles/image/_W@S2WETFST%25F%25Z21AQCI3P.JPG" />

    怎么转换为:


    <input type="image" height="131" width="139" src="\\[Server]\userfiles\image\_W@S2WETFST%25F%25Z21AQCI3P.JPG" />




    asp解法:

    '邮件正文
        strsql="select txt,Filename,File_Name from bbs where unique_id="+Request.QueryString("Unique_ID")
        
    set rs=connection.execute(strsql)
            
        myTxt 
    = rs("txt")
        
    '利用正则表达式替换img标记

    dim objRe
    set objRe = New RegExp
    '設定正則式

    objRe.Pattern 
    = "(src=)('|"&CHR(34)&"| )?(.[^'| |"&CHR(34)&"]*)(\.)(jpg|gif|png|bmp|jpeg)('|"&CHR(34)&"| |>)?"

    objRe.IgnoreCase 
    = true
    objRe.Multiline 
    = true
    objRe.Global 
    = true
    set matches = objRe.Execute(myTxt)
    newtxt 
    = myTxt
    for each match in matches
        
        cccc 
    = split(match.value,"/")
        
    if(ubound(cccc) <> 0) then
        
    '获得应该的字符串
        for i=0 to ubound(cccc)
            
    if i = 0 then
                mystr 
    = cccc(0)&"\\[server]\"
                
            
    else if  i= ubound(cccc) then
                mystr 
    = mystr&cccc(i) 
            
    else
        
                mystr 
    = mystr&cccc(i)&"\"
                
            end 
    if
        end 
    if
            
        next
        newtxt 
    = Replace(newtxt,match.value,mystr)
        end 
    if

        

    next

    set objRE = nothing


        a 
    = "<body background='\\[server]\2008back.gif'>"
        
        Body
    =a& newtxt &"</body>"
        
        

    ====================================================================

    .Net 解法:


    using System.Text.RegularExpressions;
     string   convertExp(string strTxt)
        {
           
            
    string strPattern = "(src=)('|" + (char)34 + "| )?(.[^'| |" + (char)34 + "]*)(\\.)(jpg|gif|png|bmp|jpeg)('|" + (char)34 + "| |>)?";
            
    // Compile the regular expression.
            Regex objRe=new Regex(strPattern);
            
    // Match the regular expression pattern against a text string.
            MatchCollection matches=objRe.Matches(strTxt);
            
    string mystr="";
            
    string strNewTxt = strTxt;
          
            
    foreach (Match match in matches)
            {
              
                    
    string[] strC = match.Value.Split('/');
                      
    //if it's the bottom jpg,break Foreach
                    if (strC[strC.Length - 1].ToString() == "asdf.jpg\"")
                    {
                        
    break;
                    }
                    
    if (strC.Length != 0)
                    {
                        
    for (int i = 0; i < strC.Length; i++)
                        {
                            
    if (i == 0)
                                mystr 
    = strC[0+ "\\\\[server]\\";
                            
    else if (i == strC.Length - 1)
                                mystr 
    = mystr + strC[i];
                            
    else
                                mystr 
    = mystr + strC[i] + "\\";
                        }
                        strNewTxt 
    = strNewTxt.Replace(match.Value, mystr);
                    }
               
            }
            
    return strNewTxt;


        }


    调用:

     StringBuilder sb = getMailContent(strSubject);

            lblPreview.Text 
    = convertExp(sb.ToString());



  • 相关阅读:
    用django2.1开发公司官网(上)
    vue常用手册
    xadmin+django2.0删除用户报错,get_deleted_objects() takes 3 positional arguments but 5 were given
    Vue+koa2开发一款全栈小程序(9.图书详情页)
    Vue+koa2开发一款全栈小程序(8.图书列表页)
    Vue+koa2开发一款全栈小程序(7.图书录入功能)
    Vue+koa2开发一款全栈小程序(6.个人中心)
    Vue+koa2开发一款全栈小程序(5.服务端环境搭建和项目初始化)
    java中基本类型double和对象类型Double
    vb中的除法
  • 原文地址:https://www.cnblogs.com/amadeuslee/p/3744504.html
Copyright © 2011-2022 走看看