Mid Function, Mid Statement

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

Syntax:


Mid (Text As String, Start As Long [, Length As Long])
Mid (Text As String, Start As Long, Length As Long, 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 ExampleMid_Function_and_Statement
  original_text = "This is the original Text"
' Mid as function 
  msgbox Mid( original_text , 13, 8) ' returns the word original
  msgbox original_text               ' original_text not modified
' Mid as statement 
  Mid( original_text, 13, 8, "new" )
  msgbox original_text               ' returns This is the new Text
End Sub