我正在尝试从访问中的以下字符串中提取date
。不知道怎么做,因为所有的都是不同的格式。
AT (ALL LOCATION) (XYZ) (15TH FEB10) (some).xlsx
AT) (XYZ) (DEC-15) (bdd).xlsx
(AT SOUTH) (XYZ) (FEB11 TO MAR11) (some).xlsx
(AT) (XYZ) (APR13-DEC13) (some - sky).xlsx
答案 0 :(得分:0)
此函数返回包含数字的括号之间第一次出现的字符串:
Public Function bracketedWordWithNumber(strIn As String) As String
Dim arr() As String, x As Integer
'test for number in parentheses
If Not strIn Like "*(*#*)*" Then Exit Function
'remove file extension: everything after last dot '.'
If InStr(strIn, ".") > 0 Then strIn = Left(strIn, InStrRev(strIn, ".") - 1)
'remove right parentheses ')'
strIn = Replace(strIn, ")", "")
'split into array on left parentheses '('
arr = Split(strIn, "(")
'iterate array
For x = 0 To UBound(arr)
'find strings with numbers
If arr(x) Like "*#*" Then
'return match
bracketedWordWithNumber = arr(x)
'stop after the first match
Exit Function
End If
Next x
End Function
MSDN: Split Function (VBA)
Microsoft.com: Like Operator (Visual Basic)
MSDN: InStr Function (VBA)
MSDN: Replace Function (VBA)