-
I've got the Split function all figured out, but can't get the Join function working. As usual, MSDN Library was no help whatsoever, so I'm turning to the forums.
Please could someone give me an example of the Join function at work?
Thanks in advance!!
-
Basically, you pass it an array (usually created with th Split Function) and it joins all the array's elements with the delimiter (usually a space):
Code:
Dim Joined As String, StartArr(2) As String
StartArr(0) = "Hello"
StartArr(1) = "There,"
StartArr(2) = "CyberSurfer"
Joined = Join(StartArr, " ")
'Joined = "Hello There, CyberSurfer"
If necessary you could use a different delimiter:
Code:
Dim Joined As String, StartArr(2) As String
StartArr(0) = "Hello"
StartArr(1) = "There,"
StartArr(2) = "CyberSurfer"
Joined = Join(StartArr, "@")
'Joined = "Hello@There,@CyberSurfer"
What it basically does is iterate through all of the elements, appending them to the delimiter and the string which the previous elements made:
Code:
Function MyJoin(Arr() As String, Delimter) As String
'This is the same as Join:
Dim TmpStr As String
TmpStr = TmpStr & LBound(Arr)
For i = LBound(Arr) + 1 To UBound(Arr)
TmpStr = TmpStr & Delimter & Arr(i)
Next:
End Function
I hope you understand it better, now.
Me.