Mid是Visual Basic和Microsoft Excel中的一个字符串函数,作用是从一个字符串中截取出指定数量的字符。
VB中语法:
Mid(String As Variant, Start As Long, [Length As Variant]) As Variant
Mid$(String As String, Start As Long, [Length As Variant]) As String
VB示例:
下面的示例展示了VB中如何使用Mid函数。其中所有的“Mid”都可以用“Mid$”代替。
DimvAsString
v=Mid("VisualBasic",0,12)'提示实时错误5
v=Mid("VisualBasic",1,6)'v的值为"Visual"
v=Mid("VisualBasic",1,20)'v的值为"VisualBasic"
v=Mid("VisualBasic",8)'v的值为"Basic"
v=Mid("VisualBasic",15)'v的值为空字符串
v=Mid("中文VB",2,2)'v的值为"文V"