返回包含指定数目的子字符串的从零开始的一维数组。
语法
拆分 (表达式, [ delimiter, [ limit, [ compare ]]])
TimeSerial 函数语法具有以下命名参数:
| Part | 说明 | 
|---|---|
| expression | 必填。 包含子字符串和分隔符的字符串表达式。 如果 expression 是零长度字符串 (""),则 Split 返回空数组,即不包括任何元素和数据的数组。 | 
| 分隔符 | 可选。 用于标识子字符串限制的 String 字符。 如果省略,则假定空格符 (" ") 为分隔符。 如果 delimiter 是零长度字符串,则返回包含完整 expression 字符串的只含单一元素的数组。 | 
| 限制 | 可选。 要返回的子字符串数;-1 指示返回所有子字符串。 | 
| compare | 可选。 指示计算子字符串时要使用的比较类别的数值。 请参阅“设置”部分以了解各个值。 | 
设置
compare 参数可以包含以下值:
| 常量 | 值 | 说明 | 
|---|---|---|
| vbUseCompareOption | -1 | 使用 Option Compare 语句的设置来执行比较。 | 
| vbBinaryCompare | 0 | 执行二进制比较。 | 
| vbTextCompare | 1 | 执行文本比较。 | 
| vbDatabaseCompare | 2 | 仅用于 Microsoft Access。 根据数据库中的信息执行比较。 | 
示例
此示例演示如何使用 Split 函数。
Dim strFull As String
Dim arrSplitStrings1() As String
Dim arrSplitStrings2() As String
Dim strSingleString1 As String
Dim strSingleString2 As String
Dim strSingleString3 As String
Dim i As Long
strFull = "Dow - Fonseca - Graham - Kopke - Noval - Offley - Sandeman - Taylor - Warre"    ' String that will be used. 
arrSplitStrings1 = Split(strFull, "-")      ' arrSplitStrings1 will be an array from 0 To 8. 
                                            ' arrSplitStrings1(0) = "Dow " and arrSplitStrings1(1) = " Fonesca ". 
                                            ' The delimiter did not include spaces, so the spaces in strFull will be included in the returned array values. 
arrSplitStrings2 = Split(strFull, " - ")    ' arrSplitStrings2 will be an array from 0 To 8. 
                                            ' arrSplitStrings2(0) = "Dow" and arrSplitStrings2(1) = "Fonesca". 
                                            ' The delimiter includes the spaces, so the spaces will not be included in the returned array values. 
'Multiple examples of how to return the value "Kopke" (array position 3). 
strSingleString1 = arrSplitStrings2(3)      ' strSingleString1 = "Kopke". 
strSingleString2 = Split(strFull, " - ")(3) ' strSingleString2 = "Kopke".
                                            ' This syntax can be used if the entire array is not needed, and the position in the returned array for the desired value is known. 
For i = LBound(arrSplitStrings2, 1) To UBound(arrSplitStrings2, 1)
    If InStr(1, arrSplitStrings2(i), "Kopke", vbTextCompare) > 0 Then
        strSingleString3 = arrSplitStrings2(i)
        Exit For
    End If 
Next i
另请参阅
支持和反馈
有关于 Office VBA 或本文档的疑问或反馈? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。