Join 函数

将字符串数组中的多个子字符串组合成一个字符串。

语法:


Join (Text As String Array, delimiter)

返回值:

String

参数:

Text」:字符串数组。

delimiter (可选)」: 用于分隔返回字符串中的子字符串的字符串字符。默认的分隔字符是空格。如果分隔字符是一个零长度字符串 "",子串将紧密相接,相互间无分隔符。

示例:


Dim a(3)
Sub main()
    a(0) = "ABCDE"
    a(1) = 42
    a(2) = "MN"
    a(3) = "X Y Z"
    JStr = Join1()
    Call Show(JStr, Split1(JStr))
    JStr = Join2()
    Call Show(JStr, Split1(JStr))
    JStr = Join3()
    Call Show(JStr, Split1(JStr))
End Sub
 
Function Join1()
    Join1 = Join(a(), "abc")
End Function
 
Function Join2()
    Join2 = Join(a(), ",")
End Function
 
Function Join3()
    Join3 = Join(a())
End Function
 
Function Split1(aStr)
    Split1 = Split(aStr, "D")
End Function
 
Sub Show(JoinStr, TheArray)
    l = LBound(TheArray)
    u = UBound(TheArray)
    total$ = "=============================" + Chr$(13) + JoinStr + Chr$(13) + Chr$(13)
    For i = l To u
        total$ = total$ + TheArray(i) + Str(Len(TheArray(i))) + Chr$(13)
    Next i
    MsgBox total$
End Sub

请支持我们!