日期:2014-05-17  浏览次数:21010 次

急,如何取我要的字符串
<IMG src="/UploadFile/11.jpg" border=0><IMG src="/UploadFile/232.jpg" border=0><IMG src="/UploadFile/4112.jpg" border=0>

上面我要取出到
/UploadFile/11.jpg
/UploadFile/232.jpg
/UploadFile/4112.jpg

并写成img1=/UploadFile/11.jpg&img2=/UploadFile/232.jpg&img3=/UploadFile/4112.jpg&

我写一下代码,要的是asp代码,或是jsp的,不过最好是asp代码更好。

------解决方案--------------------
用Split 以 引号 来分割字符串,然后就可以获取你想要的了啊
------解决方案--------------------
VBScript code

<%
dim str
str="<IMG src='/UploadFile/11.jpg' border=0> <IMG src='/UploadFile/232.jpg' border=0> <IMG src='/UploadFile/4112.jpg' border=0>"
myarry=split(str,"'")
response.write("img1="&myarry(1)&"&img2="&myarry(3)&"&img3="&myarry(5))&"&"
%>

------解决方案--------------------
VBScript code
Function GetImgs(str)
    Dim a(), regex, i, matches, match
    Set regex = New RegExp
    regex.Pattern = "<img src\=""([^""]+)"" border=0>"
    regex.IgnoreCase = True
    regex.Global = True
    Set matches = regex.Execute(str)
    ReDim a(matches.Count-1)
    For i = 0 To matches.Count - 1
        a(i) = "img" & (i+1) & "=" & matches(i).Submatches(0)
    Next
    Set matches = Nothing
    Set regex = Nothing
    GetImgs = Join(a, "&")
End Function

Dim str
str = "<IMG src=""/UploadFile/11.jpg"" border=0><IMG src=""/UploadFile/232.jpg"" border=0><IMG src=""/UploadFile/4112.jpg"" border=0>"

Response getImgs(str)

------解决方案--------------------
VBScript code
dim str
str="<IMG src=""/UploadFile/11.jpg"" border=0> <IMG src=""/UploadFile/232.jpg"" border=0> <IMG src=""/UploadFile/4112.jpg"" border=0>"
ar=split(str,"""")
str2 = ""
For i = 0 To UBound(ar)
    If InStr(ar(i),"/UploadFile/")>0 Then 
        If str2 = "" Then
            str2 = ar(i)
        Else
            str2 = str2 & "," & ar(i)
        End If 
    End If 
next
response.write str2

------解决方案--------------------


我说LZ,现在你给我的是一串字符,放到程序里去肯定要改一下引号,不然怎么用?

如果你的一串字符是人工输的,就可以人工改,如果是从数据库里调出来的就不同了
------解决方案--------------------
<IMG src="/UploadFile/11.jpg" border=0>
使用replace将<IMG src="和" border=0>替换为空就行了
------解决方案--------------------
VBScript code
Dim input, output, i
input = "<IMG src=""/UploadFile/11.jpg"" border=0> <IMG src=""/UploadFile/232.jpg"" border=0> <IMG src=""/UploadFile/4112.jpg"" border=0> "
 Dim re, m
 Set re = new Regexp
 re.pattern = "<img\s+src=""([^""]+)"
 re.IgnoreCase = True
 re.Global = True
 Set m = re.Execute(input)

 For i = 0 To m.count-1
    output = output & "img" & i+1 & "=" & m(i).Submatches(0) & "&"
 Next 
Response.Write "<script language='javascript'>alert('" & output & "');</script>"
Set re = Nothing 
Set m = Nothing