Join Function (Visual Basic)
Returns a string created by joining a number of substrings contained in an array.
Function Join(
ByVal SourceArray() As { Object | String },
Optional ByVal Delimiter As String = " "
) As String
Parameters
SourceArray
Required. One-dimensional array containing substrings to be joined.Delimiter
Optional. Any string, used to separate the substrings in the returned string. If omitted, the space character (" ") is used. If Delimiter is a zero-length string ("") or Nothing, all items in the list are concatenated with no delimiters.
Exceptions
Exception type |
Error number |
Condition |
---|---|---|
SourceArray is not one dimensional. |
See the "Error number" column if you are upgrading Visual Basic 6.0 applications that use unstructured error handling. (You can compare the error number against the Number Property (Err Object).) However, when possible, you should consider replacing such error control with Structured Exception Handling Overview for Visual Basic.
Remarks
There is a parity between the Join and Split functions. The Join function takes an array of strings and joins them using a delimiter string, to return a single string. The Split function takes a string and separates it at the delimiter, to return an array of strings. However, a key difference is that Join can concatenate strings with any delimiter string, Split can only separate strings using a single character delimiter.
Example
The following example demonstrates how to use the Join function to create a list from several strings.
Dim TestItem() As String = {"Pickle", "Pineapple", "Papaya"}
' Returns "Pickle, Pineapple, Papaya"
Dim TestShoppingList As String = Join(TestItem, ", ")
Requirements
Namespace:Microsoft.VisualBasic
**Module:**Strings
Assembly: Visual Basic Runtime Library (in Microsoft.VisualBasic.dll)