/** 给content的img添加a
* @param content
* @return
*/
private String updateContent(String content) {
StringBuffer result = new StringBuffer();
String temp = "";
int begin = content.toLowerCase().indexOf("<img");
while(begin != -1) {
result.append(content.substring(0, begin));
temp = content.substring(begin);
int imgSrcBegin = temp.toLowerCase().indexOf("src=") + 5;
String imgUrl = temp.substring(imgSrcBegin, imgSrcBegin + 50);
imgUrl = imgUrl.toLowerCase().replace("/s/", "/");
imgUrl = "<a rel=\"example_group\" href=\""+imgUrl+"\" >";
result.append(imgUrl);
int imgEnd = temp.toLowerCase().indexOf("/>") + 2;
String img = temp.substring(0, imgEnd);
result.append(img);
result.append("</a>");content = temp.substring(imgEnd, temp.length());
begin = content.toLowerCase().indexOf("<img");
if(begin == -1)
result.append(content);
}return result.toString();

这个应该是.NET版本用的吧 想在ASP实现这样的功能  这个函数应该怎么修改啊》
请高手帮忙.NETASPStringstringbuffer

解决方案 »

  1.   

    这程序是Java写的。代码就不转换了,提示你几点
    StringBuilder用来字符串拼接
    比如
    result.append(img);
    result.append("</a>");
    =>
    result = result & img
    result = result & "</a>"IndexOf对应Instr()
    ToLowCase对应LCase()
    SubString对应Mid()别的你应该都会。
      

  2.   


    版主麻烦帮我看下 我转化的代码 那边还有问题使用的时候提示类型错误<%
    function updateContent(content) 
     dim result
     dim temp:temp = ""
     int begin = Instr(LCase(content),"<img")
       while begin <> -1 
         result=result & Mid(content,0, begin)
         temp = Mid(content,begin)
     int imgSrcBegin = Instr(LCase(temp),"src=") + 5
     dim imgUrl:imgUrl = Mid(temp,imgSrcBegin, imgSrcBegin + 50)
     imgUrl = replace(LCase(imgUrl),"/s/", "/") 
     imgUrl = "<a href=\""&imgUrl&"\" >" 
     result=result&imgUrl 
     int imgEnd = Instr(LCase(temp),"/>") + 2
     String img = Mid(temp,0, imgEnd)
     result=result & img 
     result=result & "</a>"
     content = Mid(temp,imgEnd, len(temp))
     begin = Instr(LCase(content),"<img") 
     if begin = -1 then result=result&content
    wend

    updateContent=result   
    end function
    %>
      

  3.   


    请版主榜我看下 我转化的代码 那边还有问题?
    <%
    function updateContent(content) 
     dim result
     dim temp:temp = ""
     int begin = Instr(LCase(content),"<img")
       while begin <> -1 
         result=result & Mid(content,0, begin)
         temp = Mid(content,begin)
     int imgSrcBegin = Instr(LCase(temp),"src=") + 5
     dim imgUrl:imgUrl = Mid(temp,imgSrcBegin, imgSrcBegin + 50)
     imgUrl = replace(LCase(imgUrl),"/s/", "/") 
     imgUrl = "<a href=\""&imgUrl&"\" >" 
     result=result&imgUrl 
     int imgEnd = Instr(LCase(temp),"/>") + 2
     String img = Mid(temp,0, imgEnd)
     result=result & img 
     result=result & "</a>"
     content = Mid(temp,imgEnd, len(temp))
     begin = Instr(LCase(content),"<img") 
     if begin = -1 then result=result&content
    wend

    updateContent=result   
    end function
    %>
      

  4.   


    版主麻烦帮我看下 我转化的代码 那边还有问题使用的时候提示类型错误<%
    function updateContent(content) 
     dim result
     dim temp:temp = ""
     int begin = Instr(LCase(content),"<img")
       while begin <> -1 
         result=result & Mid(content,0, begin)
         temp = Mid(content,begin)
     int imgSrcBegin = Instr(LCase(temp),"src=") + 5
     dim imgUrl:imgUrl = Mid(temp,imgSrcBegin, imgSrcBegin + 50)
     imgUrl = replace(LCase(imgUrl),"/s/", "/") 
     imgUrl = "<a href=\""&imgUrl&"\" >" 
     result=result&imgUrl 
     int imgEnd = Instr(LCase(temp),"/>") + 2
     String img = Mid(temp,0, imgEnd)
     result=result & img 
     result=result & "</a>"
     content = Mid(temp,imgEnd, len(temp))
     begin = Instr(LCase(content),"<img") 
     if begin = -1 then result=result&content
    wend

    updateContent=result   
    end function
    %>

    function updateContent(content) 
     dim result
     dim temp:temp = "" <--这里也不能这样定义只要 dim temp就行
     int begin = Instr(LCase(content),"<img") <--这里的int是错的 去掉int
       while begin <> -1 
         result=result & Mid(content,0, begin)
         temp = Mid(content,begin)
         int imgSrcBegin = Instr(LCase(temp),"src=") + 5 <--同样int去掉
         dim imgUrl:imgUrl = Mid(temp,imgSrcBegin, imgSrcBegin + 50) 没必要写上dim imgUrl:这个去掉
         imgUrl = replace(LCase(imgUrl),"/s/", "/") 
         imgUrl = "<a href=\""&imgUrl&"\" >" 
         result=result&imgUrl 
         int imgEnd = Instr(LCase(temp),"/>") + 2 这里一样 int去掉
         String img = Mid(temp,0, imgEnd) 这里String去掉
         result=result & img 
         result=result & "</a>"
         content = Mid(temp,imgEnd, len(temp))
         begin = Instr(LCase(content),"<img") 
         if begin = -1 then result=result&content
        wend
         
        updateContent=result      
    end functionASP没有类型定义的只能Dim 变量int String这些在ASP里面都没有的
      

  5.   


    版主麻烦帮我看下 我转化的代码 那边还有问题使用的时候提示类型错误<%
    function updateContent(content) 
     dim result
     dim temp:temp = ""
     int begin = Instr(LCase(content),"<img")
       while begin <> -1 
         result=result & Mid(content,0, begin)
         temp = Mid(content,begin)
     int imgSrcBegin = Instr(LCase(temp),"src=") + 5
     dim imgUrl:imgUrl = Mid(temp,imgSrcBegin, imgSrcBegin + 50)
     imgUrl = replace(LCase(imgUrl),"/s/", "/") 
     imgUrl = "<a href=\""&imgUrl&"\" >" 
     result=result&imgUrl 
     int imgEnd = Instr(LCase(temp),"/>") + 2
     String img = Mid(temp,0, imgEnd)
     result=result & img 
     result=result & "</a>"
     content = Mid(temp,imgEnd, len(temp))
     begin = Instr(LCase(content),"<img") 
     if begin = -1 then result=result&content
    wend

    updateContent=result   
    end function
    %>

    function updateContent(content) 
     dim result
     dim temp:temp = "" <--这里也不能这样定义只要 dim temp就行
     int begin = Instr(LCase(content),"<img") <--这里的int是错的 去掉int
       while begin <> -1 
         result=result & Mid(content,0, begin)
         temp = Mid(content,begin)
         int imgSrcBegin = Instr(LCase(temp),"src=") + 5 <--同样int去掉
         dim imgUrl:imgUrl = Mid(temp,imgSrcBegin, imgSrcBegin + 50) 没必要写上dim imgUrl:这个去掉
         imgUrl = replace(LCase(imgUrl),"/s/", "/") 
         imgUrl = "<a href=\""&imgUrl&"\" >" 
         result=result&imgUrl 
         int imgEnd = Instr(LCase(temp),"/>") + 2 这里一样 int去掉
         String img = Mid(temp,0, imgEnd) 这里String去掉
         result=result & img 
         result=result & "</a>"
         content = Mid(temp,imgEnd, len(temp))
         begin = Instr(LCase(content),"<img") 
         if begin = -1 then result=result&content
        wend
         
        updateContent=result      
    end functionASP没有类型定义的只能Dim 变量int String这些在ASP里面都没有的
    修改为这样了 还是无法运行。function updateContent(content) 
     dim result
     dim temp
     begin = Instr(LCase(content),"<img")
       while begin <> -1 
         result=result & Mid(content,0, begin)
         temp = Mid(content,begin)
     imgSrcBegin = Instr(LCase(temp),"src=") + 5
     imgUrl = Mid(temp,imgSrcBegin, imgSrcBegin + 50)
     imgUrl = replace(LCase(imgUrl),"/s/", "/") 
     imgUrl = "<a href=\""&imgUrl&"\" >" 
     result=result&imgUrl 
     imgEnd = Instr(LCase(temp),"/>") + 2
     img = Mid(temp,0, imgEnd)
     result=result & img 
     result=result & "</a>"
     content = Mid(temp,imgEnd, len(temp))
     begin = Instr(LCase(content),"<img") 
     if begin = -1 then result=result&content
    wend
     updateContent=result
    end function
      

  6.   

    VB的mid函数下标从1开始的,而Java等语言的SubString从0开始的。
      

  7.   

    程序报错是 begin = Instr(LCase(content),"<img") 这行 提示 :变量未定义: 'begin'请问什么错误?