VBA. How to find position of first digit in string

前端 未结 6 1225
陌清茗
陌清茗 2020-12-31 08:47

I have string \"ololo123\". I need get position of first digit - 1. How to set mask of search ?

6条回答
  •  Happy的楠姐
    2020-12-31 09:25

    You could try regex, and then you'd have two problems. My VBAfu is not up to snuff, but I'll give it a go:

    Function FirstDigit(strData As String) As Integer
        Dim RE As Object REMatches As Object
    
        Set RE = CreateObject("vbscript.regexp")
        With RE
            .Pattern = "[0-9]"
        End With
    
        Set REMatches = RE.Execute(strData)
        FirstDigit = REMatches(0).FirstIndex
    End Function
    

    Then you just call it with FirstDigit("ololo123").

提交回复
热议问题