当前位置:首页 > Excel函数教程 > 提取字符串中汉字、英文与数字的函数

提取字符串中汉字、英文与数字的函数

来源:Excel中文网 作者:Excelcn 发布时间:2006-04-12
 语法: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 
| 网站地图 All Rights Reserved. Powered by Excel中文网