Mid Function, Mid Statement

傳回字串型表示式的指定部份 (Mid 函式),或用另一字串代替字串型表示式的指定部份 (Mid 陳述式)。

Syntax:


Mid(Text As String, Start As Integer[, Length As Integer]) 或 Mid(Text As String, Start As Integer , Length As Integer, Text As String)

Return value:

字串型 (僅適用於函式)

Parameters:

Text:要修改的任意字串型表示式。

Start: Numeric expression that indicates the character position within the string where the string portion that you want to replace or to return begins. The minimum allowed value is 1. The maximum allowed value is 2,147,483,648.

Length: Numeric expression that returns the number of characters that you want to replace or return. The maximum allowed value is 2,147,483,648.

如果不指定 Mid 函式中的 Length 參數,則傳回字串型表示式中從開始位置到字串結尾的所有字元。

如果 Mid 陳述式中的 Length 參數小於要代替的文字長度,文字將縮短到指定的長度。

Text:用於代替字串型表示式的字串 (Mid 陳述式)。

錯誤代碼:

5 無效的程序呼叫

Example:


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

Please support us!