Mid Function, Mid Statement
傳回字串型表示式的指定部份 (Mid 函式),或用另一字串代替字串型表示式的指定部份 (Mid 陳述式)。
語法:
Mid(Text As String, Start As Integer[, Length As Integer]) 或 Mid(Text As String, Start As Integer , Length As Integer, Text As String)
傳回值類型:
字串型 (僅適用於函式)
參數:
Text:要修改的任意字串型表示式。
Start:數值型表示式,表示字串中將要被代替或傳回的字串部份所對應的起始字元位置。最大限值為 65535。
Length:整型表示式,傳回要代替或傳回的字元數目。
如果不指定 Mid 函式中的 Length 參數,則傳回字串型表示式中從開始位置到字串結尾的所有字元。
如果 Mid 陳述式中的 Length 參數小於要代替的文字長度,文字將縮短到指定的長度。
Text:用於代替字串型表示式的字串 (Mid 陳述式)。
示例:
Sub ExampleUSDate
Dim sInput As String
Dim sUS_date As String
sInput = InputBox("Please input a date in the international format 'YYYY-MM-DD'")
sUS_date = Mid(sInput, 6, 2)
sUS_date = sUS_date & "/"
sUS_date = sUS_date & Right(sInput, 2)
sUS_date = sUS_date & "/"
sUS_date = sUS_date & Left(sInput, 4)
MsgBox sUS_date
End Sub