C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
And: The resulting string has the delimiter placed between all the elements—but not at the start or end.
ArrayInfo: Join requires a delimiter character and a collection of strings. It places this separator in between the strings in the result.
VB.NET program that uses String.Join function
Module Module1
Sub Main()
' Three-element array.
Dim array(2) As String
array(0) = "Dog"
array(1) = "Cat"
array(2) = "Python"
' Join array.
Dim result As String = String.Join(",", array)
' Display result.
Console.WriteLine(result)
End Sub
End Module
Output
Dog,Cat,Python
Tip: Arguments after the first are joined together—the first is the delimiter.
VB.NET program that joins ParamArray
Module Module1
Sub Main()
' Join array.
Dim result As String = String.Join("-", "Dot", "Net", "Perls")
' Display result.
Console.WriteLine(result)
End Sub
End Module
Output
Dot-Net-Perls
Info: This String.Join function converts each object to a string and then joins those strings together.
VB.NET program that joins object ParamArray
Module Module1
Sub Main()
' Join array.
Dim result As String = String.Join("/", 1, 2, 3, "VB.NET")
' Display result.
Console.WriteLine(result)
End Sub
End Module
Output
1/2/3/VB.NET
VB.NET program that joins List
Module Module1
Sub Main()
' List.
Dim list As List(Of String) = New List(Of String)
list.Add("Dot")
list.Add("Net")
list.Add("Perls")
' Join list.
Dim result As String = String.Join("*", list)
' Display result.
Console.WriteLine(result)
End Sub
End Module
Output
Dot*Net*Perls