Mid 函数, Mid 语句

返回字符串表达式的指定部分 (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: 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 无效的过程调用

示例:


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

请支持我们!