【Asp】ASP截取字符 截取字符之间的字符

admin 2021年4月3日19:03:11评论66 views字数 1387阅读4分37秒阅读模式

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,"
startnub=instr(str,"

endnub=instr(str,"
") 
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,"(.*)") '应该可以得到一个字符串变量href,将所有连接用||区分开,下面将其变为数组

文章来源于lcx.cc:【Asp】ASP截取字符 截取字符之间的字符

相关推荐: WScript.Shell: 对象的run和exec使用详解

    vbScript 中 WScript.Shell 对象的 run 和 exec 函数功能使用详解 函数声明:     Set Ws = CreateObject("Wscript.Shell")     Function Exec(ByVal Comm…

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2021年4月3日19:03:11
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   【Asp】ASP截取字符 截取字符之间的字符https://cn-sec.com/archives/319726.html

发表评论

匿名网友 填写信息