「安卓按键精灵」几种字符串提取的方法(源码)

截取法提取两个字符串之间的内容

TracePrint GetStrAB("如果想要写成一行代码,那么就可以用冒号连接","想要","代码")

Function GetStrAB(str,StrA,StrB)

If UTF8.InStr(1, str, StrA)>0 and utf8.instr(1,str,StrB) > 0 Then

Dim m=utf8.instr(1,Str,StrA)

Dim n=utf8.instr(m,Str,StrB)

GetStrAB=utf8.mid(str,m+utf8.len(StrA),n-m-utf8.len(StrA))

End If

End Function

分割法提取字符串

TracePrint SplitStrAB("如果想要写成一行代码,那么就可以用冒号连接","想要","代码")

Function SplitStrAB(str, StrA, StrB)

If UTF8.InStr(1, str, StrA) > 0 and UTF8.InStr(1, str, StrB) > 0 Then

Dim arr_A=split(str,StrA)

Dim arr_B=split(arr_A(1),StrB)

SplitStrAB=arr_B(0)

end if

End Function

取多组两个字符串之间的内容
Dim arr=GetStrArr("如果(公众号3分钟学堂)写成一行(代码),那么就(可以)用冒号连接","(",")")

For Each k In arr

TracePrint k

Next

Function GetStrArr(str, StrA, StrB)

If UTF8.InStr(1, str, StrA) > 0 and UTF8.InStr(1, str, StrB) > 0 Then

Dim str_arr=array()

Dim n=0

Dim arr_A=split(str,StrA)

Dim arr_B

For i = 1 To UBOUND(arr_A)

If InStr(1,arr_A(i),StrB) > 0 Then

arr_B = Split(arr_A(i), StrB)

str_arr(n) = arr_B(0)

n=n+1

End If

Next

GetStrArr=str_arr

end if

End Function

提取数字

TracePrint GetNum("如果7991312_ba@326d1b都是a2a693880a25f%1330b955526连接")

Function GetNum(str)

Dim Num

For i = 1 To UTF8.Len(str)

If IsNumeric(utf8.StrGetAt(str,i)) Then

Num=Num&utf8.StrGetAt(str,i)

End If

Next

GetNum=Num

End Function

提取字母

TracePrint GetZm("如果7991312_ba@326d1b都是a2a693880a25f%1330b955526连接")

Function GetZm(str)

Dim zm

For i = 1 To UTF8.Len(str)

If 64 < CInt(Asc(UTF8.StrGetAt(str, i))) < 91 or 96 < CInt(Asc(UTF8.StrGetAt(str, i))) < 123 Then

zm=zm&utf8.StrGetAt(str,i)

End If

Next

GetZm=zm

End Function

提取汉字

TracePrint GetCN("如果7991312_ba@326d1b都是a2a693880a25f%1330b955526连接")

Function GetCN(str)

Dim CN

For i = 1 To UTF8.Len(str)

If Len(UTF8.StrGetAt(str, i)) = 3 Then

CN=CN&UTF8.StrGetAt(str, i)

End If

Next

GetCN=CN

End Function

正则提取数字

import"shanhai.lua"

Dim str="如果7991312_ba@326d1b都是a2a693880a25f%1330b955526连接"

dim arr= shanhai.RegexFind(str,"%d+")

TracePrint join(arr,"")

正则提取字母

import"shanhai.lua"

Dim str="如果7991312_ba@326d1D都是a2a693880a25f%1330b955526连接"

dim arr= shanhai.RegexFind(str,"%a+")

TracePrint join(arr,"")

正则提取汉字

import"shanhai.lua"

Dim str="如果7991312_ba@326d1D都是a2a693880a25f%1330b955526连接"

dim arr= shanhai.RegexFind(str,"[\128-\254]+")

TracePrint join(arr,"")

本期文章是源码分享的形式,感兴趣的朋友可以复制源码在按键中运行一下,自己照着去写写就可以学会。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值