如果 你是想返回 “03年15月”Option ExplicitPrivate Sub Command1_Click() Dim s As String s = "3年15月" s = a(s) MsgBox s End SubPrivate Function a(s As String) As String Dim i As Integer Dim s1 As String, s2 As String i = InStr(1, s, "年") If i > 0 Then s1 = Mid(s, 1, i - 1) If Len(s1) = 1 Then s1 = "0" & s1
s2 = Mid(s, i + 1) i = InStr(1, s2, "月") If i > 0 Then s2 = Mid(s2, 1, i - 1) If Len(s2) = 1 Then s2 = "0" & s2 End If
s = Format("3年5月", "YY年MM月")
03年05月
Dim s As String
s = "3年15月"
s = a(s)
MsgBox s
End SubPrivate Function a(s As String) As String
Dim i As Integer
Dim s1 As String, s2 As String
i = InStr(1, s, "年")
If i > 0 Then
s1 = Mid(s, 1, i - 1)
If Len(s1) = 1 Then s1 = "0" & s1
s2 = Mid(s, i + 1)
i = InStr(1, s2, "月")
If i > 0 Then
s2 = Mid(s2, 1, i - 1)
If Len(s2) = 1 Then s2 = "0" & s2
End If
a = s1 & "年" & s2 & "月"
End If
End Function
03年15月
format("03年15月")
也是03年15月