按键精灵_字符串提取

提取字符串之间的内容(推荐)

​MsgBox GetStrAB("http://www.dayanzai.me/rufus.html", "http://", "/")
Function GetStrAB(Str, StrA, StrB)
  If InStr(Str,StrA)>0 And InStr(Str,StrB)>0 Then GetStrAB=Split(Split(Str,StrA)(1),StrB)(0)
End Function

InstrRev从右往左取位置

Dim 字符串1, 字符串2, MyPos
字符串1 ="D:\0.万能爆破\启动弹出对话框.exe"            '要在其中搜索的字符串。
字符串2 = "\"                        ' 搜索 "\"。
'文本比较从最后一个字符开始。返回 12。
MessageBox InstrRev(字符串1, 字符串2, -1, 1)

Dim 字符串3, 字符串4, MyPos1
字符串3 ="C:\W32DSM.exe"            '要在其中搜索的字符串。
字符串4 = "\"                        ' 搜索 "\"。
'文本比较从最后一个字符开始。返回 12。
MessageBox InstrRev(字符串3, 字符串4, -1, 1)

Left字符串左移操作

Dim 字符串1, 字符串2, MyPos
字符串1 ="D:\0.万能爆破\启动弹出对话框.exe"          '要在其中搜索的字符串
字符串2 = "\"                                      '搜索 "\"
'文本比较从最后一个字符开始。返回 12。
MessageBox InstrRev(字符串1, 字符串2, -1, 1)


Dim 字符串3, 字符串4, MyPos1
字符串3 ="C:\W32DSM.exe"                          '要在其中搜索的字符串
字符串4 = "\"                                     '搜索 "\"
'文本比较从最后一个字符开始。返回 12。
MessageBox InstrRev(字符串3, 字符串4, -1, 1)


Dim MyString, LeftString
MyString = "D:\0.万能爆破\启动弹出对话框.exe"
MessageBox Left(MyString, 10)                     '返回 D:\0.万能爆破\

Split分割字符串

字符串A = "D:\0.万能爆破\启动弹出对话框.exe"
字符串B = split(字符串A,"\")        '取\
For i = 1 To ubound(字符串B)
    b = split(字符串B(i), ".")     '取.之间的
    MessageBox b(0)
Next

取字符串中两字符串之间特定的内容

'查找多处:
MsgBox GetStrAB("[演]特定内容1[示]12321[演]特定内容2[示]", "[演]", "[示]")
Function GetStrAB(Str, StrA, StrB)
    Dim i,ArrStrA,Ck
    ArrStrA=Split(Str,StrA)
    For i = 1 To UBound(ArrStrA)
        If InStr(ArrStrA(i), StrB) > 0 Then Ck = Ck & Split(ArrStrA(i),StrB)(0) &"|"
    Next
    GetStrAB=Ck
End Function


'第2种版本
Text ="[演]特定内容1[示][演]特定内容2[示][演]特定内容3[示]"
MsgBox Join(两个字符串之间的内容(Text, "[演]", "[示]"), Vbcrlf)
Function 两个字符串之间的内容(原字符串, 前分割字符, 后分割字符)
    Dim 两个字符串之间的内容,Temp,TxtArray
    If InStr(原字符串, 前分割字符) > 0 and InStr(原字符串, 后分割字符) > 0 Then 
        TxtArray = Split(原字符串, 前分割字符)
        For i = 1 To UBound(TxtArray)
            Temp = Temp & Split(TxtArray(i), 后分割字符)(0) & "▓"
        Next
    ElseIf InStr(原字符串, 前分割字符) > 0 Then
        Temp = Split(原字符串, 前分割字符)(1)&"▓" 
    ElseIf InStr(原字符串, 后分割字符) > 0 Then
        Temp = Split(原字符串, 后分割字符)(0) & "▓"
    Else 
        Temp = 原字符串 & "▓"
    End If
    两个字符串之间的内容 = Split(Temp,"▓")
End Function


'版本3
MsgBox GetStrAB("[演]特定内容1[示]12321[演]特定内容2[示]", "[演]", "[示]")
Function GetStrAB(Str, StrA, StrB)
    Dim i,ArrStrA,Ck
    ArrStrA=Split(Str,StrA)
    For i = 1 To UBound(ArrStrA)
        If InStr(ArrStrA(i), StrB) > 0 Then Ck = Ck & Split(ArrStrA(i),StrB)(0) &"|"
    Next
    GetStrAB=Ck
End Function

取【】之间的内容

A = "【2013/3/18】"         '【提取这里的字串】
位置1 = instr(A, "【") + 1
位置2 = instr(位置1, A, "】")
内容 = mid(A, 位置1, 位置2 - 位置1)
MessageBox "提取:" & 内容

提取数字

Str="1ab@提2#3取cd45l$$$$%d字!@s6符&串fdsa中?:的7g汉a,s3df12.a字"
Dim AAA, BBB
For i=1 to Len(Str)
    AAA = Mid(Str, i, 1)
    If IsNumeric(AAA)=True Then 
        BBB=BBB & AAA
    End If
Next
MsgBox BBB, 64 + 4096, "结果"

'另一种写法:
Dim Str, Result, AA
Str="1ab2内45.~容s6#@!$$$$#@fdsa7"
For i=1 to Len(Str)
    AA = Mid(Str, i, 1)
    If Asc(AA)>47 And Asc(AA)<57 Then
        Result = Result & AA
    End If
Next
MsgBox Result, 64+4096,"结果" 'Return 1234567

提取字符串

Dim EK
'要提取1238810280、737242782、888128319、JFDS834242
EK = "A1238810280BCSAAA737242782BSJJJDILCAA888128319BSBBLKDAIFKCAJFDS834242BJKLDFSOREGWJOE"
Msgbox Join(ExtractStr(EK, "A", "B"), vbcr)
Function ExtractStr(ALLStr, LeftStr, RightStr)  '从完整字符串中提取特征串
    Group1 = Split(ALLStr, RightStr):jj=0
    For ii = 0 To UBound(Group1)
        If Not InStr(Group1(ii),LeftStr)=0 Then
            Group2 = Split(Group1(ii), LeftStr)
            ReDim Preserve Group3(jj)
            Group3(jj) = Group2(UBound(Group2))
            jj = jj+1
        End If
    Next
    ExtractStr = Group3
End Function

'例2
Dim EK
EK = "href=""http://control.blog.sina.com.cn/admin/article/article_edit.php?blog_id=512368720100wjud"" target=""_blank"" >"
'调用
Msgbox ExtractStr(EK, "href=""", """ target=""_blank"" >")
Function ExtractStr(ALLStr, LeftStr, RightStr) '从完整字符串中提取特征串
  ExtractStr = Mid(ALLStr, InStr(ALLStr, LeftStr)+6, InStrRev(ALLStr, RightStr)-InStr(ALLStr, LeftStr)-6)
End Function 

'上面函数只会取最左特征到最右特征之间的字符串

提起字符串中的字母

str="1Aa23aWds中国Dfa/*`zszZf"
For i=1 to Len(str)
    LString = Mid(str, i, 1)
    AA = Asc(LString)
    If (AA >= 65 and AA<=90) Or (AA >= 97 and AA<=122) Then 
        Result = Result & LString 
    End If
Next
MsgBox Result, 64 + 4096, "结果"

提起字符串中的汉字

Dim Str, Result, AA
Str="1ab@提2#3取cd45l$$$$%d字!@s6符&串fdsa中?:的7g汉a,s3df12.a字"
For i=1 to Len(Str)
    AA = Mid(Str, i, 1)
    If Asc(AA)>=-20319 And Asc(AA)<=-2050 Then
        Result = Result & AA
    End If
Next
MsgBox Result, 64+4096,"结果" 'Return 1234567

正则取汉字

str = "山a里b有c322个和d尚一e次打f水 打了2233桶水"
Dim Rlt()
Dim regEx, Match, Matches, i
i = 0
Set regEx = New RegExp 
regEx.IgnoreCase = True 
Execute "regEx.Global = True"
regEx.pattern = "[\u4E00-\u9FA5]"
Set Matches = regEx.Execute(str) 
ReDim Rlt(Matches.Count)
For Each Match in Matches 
Rlt(i) = Match.Value
i = i + 1
Next
MsgBox Join(rlt,"") 

正则取字母

str = "山a里b有c322个和d尚一e次打f水 打了2233桶水"
Dim Rlt()
Dim regEx, Match, Matches, i
i = 0
Set regEx = New RegExp 
regEx.IgnoreCase = True 
Execute "regEx.Global = True"
regEx.pattern = "[a-zA-Z]"
Set Matches = regEx.Execute(str) 
ReDim Rlt(Matches.Count)
For Each Match in Matches 
Rlt(i) = Match.Value
i = i + 1
Next
MsgBox Join(rlt,"") 

正则取数字

str = "山a里b有c322个和d尚一e次打f水 打了2233桶水"
Set regEx = New RegExp 
regEx.IgnoreCase = True 
Execute "regEx.Global = True"
regEx.pattern = "\d+"
Set Matches = regEx.Execute(str) 
ReDim Rlt(Matches.Count)
For Each Match in Matches 
    Rlt(i) = Match.Value
    i = i + 1
Next
MsgBox Join(rlt, "")

 

  • 4
    点赞
  • 31
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值