|
Function GetChar(strChar As String, varType As Variant) '取值函数
Dim objRegExp As Object
Dim objMatch As Object
Dim strPattern As String
Dim arr, i, j, k
Set objRegExp = CreateObject("vbscript.regexp")
varType = LCase(varType)
Select Case varType
Case 1, "number"
strPattern = "-?\d+(\.\d+)?"
Case 2, "english"
strPattern = "[a-z]+"
Case 3, "chinese"
strPattern = "[\u4e00-\u9fa5]+"
End Select
With objRegExp
.Global = True
.IgnoreCase = True
.Pattern = strPattern
Set objMatch = .Execute(strChar)
End With
If objMatch.count = 0 Then
GetChar = ""
Exit Function
End If
ReDim arr(0 To objMatch.count - 1)
For Each cell In objMatch
arr(i) = objMatch(i)
i = i + 1
Next
k = ""
For j = 0 To UBound(arr)
If varType = 1 Then
If k = "" Then k = Val(arr(j)) Else k = k + Val(arr(j))
Else
If k = "" Then k = arr(j) Else k = k & "," & arr(j)
End If
Next j
GetChar = k
Set objRegExp = Nothing
Set objMatch = Nothing
End Function |
评分
-
1
查看全部评分
-
|