JOIN

JOIN(sourcearray [,delimiter])

Returns a text string containing all the elements in an array (String).


sourcearrayThe array of strings (String).
delimiter(Optional) The text string to use as a separator (String).

REMARKS
* After you have finished processing an array that has been split you can use this function to concatenate the elements of an array back to a string concatenation.
* The "sourcearray" must be a 1-dimensional array.
* The "sourcearray" can be zero-based or one-based ?
* If "delimiter" is left blank, then the space character (" ") is used.
* If "delimiter" = "" (zero length string) then all the items are concatenated with no separator character.
* Doesn't work when the array is declared as "Date" data type (eg Dim vaArray(5) As Date).
* Does work when the array is declared as "Variant" data type (eg Dim vaArray(5) As Variant).
* This function cannot be used with fixed length arrays. You will see the following compile-time error: 'Can not assign or coerce array of fixed-length string or user defined type to Variant'.
* You can use the ARRAY function to return an array containing specific values.
* You can use the FILTER function to return an array containing a subset of a string array based on a filter condition.
* You can use the SPLIT function to return an array containing a specified number of substrings.
* The equivalent .NET function is Microsoft.VisualBasic.Strings.Join
* For the Microsoft documentation refer to learn.microsoft.com

Dim aValues() As String 
aValues(0) = "string1"
aValues(1) = "string2"
aValues(2) = "string3"

Debug.Print Join(aValues) '= "string1 string2 string3"
Debug.Print Join(aValues," ") '= "string1 string2 string3"
Debug.Print Join(aValues, "<>") '= "string1<>string2<>string3"
Debug.Print Join(aValues, "") '= "string1string2string3"

Dim aComponents(2) As String
aComponents(0) = "C:"
aComponents(1) = "temp"
aComponents(2) = "myfile"

Dim sFullPath As String
sFullPath = Join(aComponents,"\") & ".txt"
Debug.Print sFullPath '= "C:\temp\myfile.txt"

© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited Top