Mid, MidB
返回一个String,包含从字符串中指定数量的字符。
语法:
- Mid$( string, start [ , length ] ), Mid( string, start [ , length ] )
- MidB$( string, start [ , length ] ), MidB( string, start [ , length ] )
- string
- 必需 从中返回字符的字符串表达式。如果string包含Null,则返回Null。
- start
- 必需 Long。string中开始提取部分的字符位置。如果start大于string中的字符数,Mid返回零长度字符串(
"")。 - length
- 可选 Variant(Long)。要返回的字符数。如果省略或文本中(包括start位置的字符)的字符数少于length,则返回从start位置到字符串末尾的所有字符。
带$后缀的形式返回String;不带后缀的形式返回Variant(String)。
要确定string中的字符数,请使用Len函数。
INFO
使用MidB函数处理字符串中包含的字节数据,如双字节字符集语言。参数指定的是字节数而非字符数。
TIP
使用Mid =语句替换字符串中的字符。
示例
本示例使用Mid函数从字符串中返回指定数量的字符。
vb
Dim MyString, FirstWord, LastWord, MidWords
MyString = "Mid Function Demo" ' Create text string.
FirstWord = Mid(MyString, 1, 3) ' Returns "Mid".
LastWord = Mid(MyString, 14, 4) ' Returns "Demo".
MidWords = Mid(MyString, 5) ' Returns "Function Demo".