Mid 函数 (Visual Basic for Applications) |
您所在的位置:网站首页 › mid函数Excel › Mid 函数 (Visual Basic for Applications) |
Mid 函数
项目
04/07/2023
返回一个 Variant (String),其中包含字符串中的指定数量的字符。 语法Mid(string, start, [ length ]) Mid 函数语法包含以下命名参数: Part 说明 string 必需。 从中返回字符的字符串表达式。 如果字符串包含 Null,则返回 Null。 start 必需,Long。 字符串中被视为开始部分的字符位置。 如果 start 大于字符串中的字符数,则 Mid 返回零长度字符串 ("")。 Length 可选;Variant (Long)。 要返回的字符的数目。 如果省略此部分或此部分中的数目少于文本中的 length 字符数(包括 start 处的字符),则将返回从 start 位置到字符串末尾的所有字符。 注解若要确定字符串中字符的数量,请使用 Len 函数。 注意 与在双字节字符集语言中一样,将 MidB 函数用于字符串中包含的字节数据。 参数将指定字节数,而不是指定字符数。 有关使用 MidB 的示例代码,请参阅示例主题中的第二个示例。 示例第一个示例使用 Mid 函数返回字符串中的指定数目的字符。 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".第二个示例使用 MidB 和用户定义的函数 (MidMbcs) 返回字符串中的字符。 此处的差别在于,输入字符串用 ANSI 表示,而长度用字节表示。 Function MidMbcs(ByVal str as String, start, length) MidMbcs = StrConv(MidB(StrConv(str, vbFromUnicode), start, length), vbUnicode) End Function Dim MyString MyString = "AbCdEfG" ' Where "A", "C", "E", and "G" are DBCS and "b", "d", ' and "f" are SBCS. MyNewString = Mid(MyString, 3, 4) ' Returns "CdEf" MyNewString = MidB(MyString, 3, 4) ' Returns "bC" MyNewString = MidMbcs(MyString, 3, 4) ' Returns "bCd" 另请参阅 函数 (Visual Basic for Applications) 支持和反馈有关于 Office VBA 或本文档的疑问或反馈? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。 |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |