两种去掉字符串中数字的方法(VB学习 备注)

前端之家收集整理的这篇文章主要介绍了两种去掉字符串中数字的方法(VB学习 备注)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

1、遍历每一个字符进行判断


Public Function DelNumber(ByVal s As String) As String
    Dim strL As Long
    Dim i As Long
    Dim strTemp As String
    
    On Error GoTo err
    
    strL = Len(s)
    
    DelNumber = ""
    
    For i = 0 To strL - 1
    
        strTemp = Left(Right(s,strL - i),1)
        
        If Not IsNumeric(strTemp) Then
        
            DelNumber = DelNumber & strTemp
            
        End If
        
    Next
    
    Exit Function
    
err:

    MsgBox Error
    
End Function

2、正则表达式
Public Function DelNumberReg(ByVal s As String) As String

    Dim oRegExp As Object
    Dim strDest As String,strSource As String
    
    strSource = s
    Set oRegExp = CreateObject("VBscript.RegExp")
    oRegExp.Global = True
    oRegExp.Pattern = "[0-9]*"
    
    strDest = oRegExp.Replace(strSource,"")

    DelNumberReg = strDest
       
End Function

猜你在找的VB相关文章