ASP截取字符 截取字符之間的字符

ASP截取字符:
MID函數
Mid(變量或字串符,開始字節, 結尾字節(可不填))
InStrRev(變量, "字串符")  最後出現位置
InStr(變量, "字串符") 最先出現位置
(1)左部截取left(字符串,n):n是要截取的字符個數
(2)中部截取Mid(字符串,p,n):表示從第p個字符開始截取n個字符
(3)右部截取Right(字符串,n):表示截取字符串的後n個字符
如:
left("abcdefg",3)的結果是:"abc"
mid("abcdefg",2,3)的結果是:"bcd"
right("abcdefg",3)的結果是:"efg"

ASP截取指定字符之間的字符:
Function regx(patrn, str)
Dim regEx, Match, Matches
Set regEx = New RegExp
regEx.Pattern = patrn
regEx.IgnoreCase = True
regEx.Global = True
Set Matches = regEx.Execute(str)
For Each Match in Matches
RetStr = RetStr & Match.Value & " "
Next
regx = RetStr
End Function
調用: result=regx("http.*?jpg",str) '這裏的result就是你想要的結果.


ASP循環提取指定格式字符串:
do while instr(str,"<a htef")=0
startnub=instr(str,"<a href")
endnub=instr(str,"</a>")
a(i)=mid(str,startnub,endnub-startnub)
i=i+1
str=mid(str,endnub+1)
loop
Function RegExpTest(patrn, strng) '首先是建個函數
Dim regEx, Match, Matches ' 建立變量。
Set regEx = New RegExp ' 建立正則表達式。
regEx.Pattern = patrn ' 設置模式。
regEx.IgnoreCase = True ' 設置是否區分字符大小寫。
regEx.Global = True ' 設置全局可用性。
Set Matches = regEx.Execute(strng) ' 執行搜索。
For Each Match In Matches ' 遍歷匹配集合。
RetStr = RetStr & Match.Value & "||"
Next
RegExpTest2 = RetStr
End Function
'假設你的html的原文件信息存在變量 html中
href=RegExpTest(html,"<a href=(.*)>(.*)</a>") '應該可以得到一個字符串變量href,將所有連接用||區分開,下面將其變爲數組
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章