您的位置:首页 > 其它

提取字符串中数字、中文、英文字符…

2013-11-15 16:37 357 查看
提取字符串中数字、中文、英文字符的自定义函数

Function MyGet(Srg As String, Optional n As Integer = False)

'n为1,取汉字,n为2,取字母,n为0,取数字

    Dim i As
Integer

    Dim s,
MyString As String

    Dim Bol As
Boolean

  

    For i = 1 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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: