阅: 2594 | 回: 0
等级:初学者
- 积分:0
- 财富值:0.0
- 身份:普通用户
提取字符串中汉字、英文与数字的函数
语法:myget(srg,n,start_num )
=myget(srg,1,3) ’从第3位开始取出中文字符
=myget(srg,2) ’从第1位开始取出英文字母,第3个参数省略默认为1
=myget(srg,,5) ’从第5位开始取出数字,第2个参数省略默认为0
=myget(srg) ’第2、3个参数都省略,默认为从第1位取出所有数字
Function MyGet(Srg As String, Optional n As Integer = False, Optional start_num As Integer = 1)
Dim i As Integer
Dim s, MyString As String
Dim Bol As Boolean
For i = start_num To Len(Srg)
s = Mid(Srg, i, 1)
If n = 1 Then
Bol = Asc(s) < 0
ElseIf n = 2 Then
Bol = s Like "[a-z,A-Z]"
ElseIf n = 0 Then
Bol = s Like "#"
End If
If Bol Then MyString = MyString & s
Next
MyGet = IIf(n = 1 Or n = 2, MyString, Val(MyString))
End Function
语法:myget(srg,n,start_num )
=myget(srg,1,3) ’从第3位开始取出中文字符
=myget(srg,2) ’从第1位开始取出英文字母,第3个参数省略默认为1
=myget(srg,,5) ’从第5位开始取出数字,第2个参数省略默认为0
=myget(srg) ’第2、3个参数都省略,默认为从第1位取出所有数字
Function MyGet(Srg As String, Optional n As Integer = False, Optional start_num As Integer = 1)
Dim i As Integer
Dim s, MyString As String
Dim Bol As Boolean
For i = start_num To Len(Srg)
s = Mid(Srg, i, 1)
If n = 1 Then
Bol = Asc(s) < 0
ElseIf n = 2 Then
Bol = s Like "[a-z,A-Z]"
ElseIf n = 0 Then
Bol = s Like "#"
End If
If Bol Then MyString = MyString & s
Next
MyGet = IIf(n = 1 Or n = 2, MyString, Val(MyString))
End Function
我的个性签名