C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Note: There is no comment at the end, only between two elements in the list at each location.
Tip: You can make this example compile in .NET 3.5 by using vals.ToArray() as the second argument to String.Join.
VB.NET program that uses String.Join
Module Module1
Sub Main()
' Create list of three strings.
Dim vals As List(Of String) = New List(Of String)
vals.Add("dot")
vals.Add("net")
vals.Add("Codex")
' Use string join function that receives IEnumerable.
Dim value As String = String.Join(",", vals)
Console.WriteLine(value)
End Sub
End Module
Output
dot,net,Codex
Then: We invoke the ToString function on the StringBuilder instance to acquire the result String.
StringBuilder ExamplesPlease note: The result string has a delimiter at the end—this may not be desirable.
VB.NET program that uses StringBuilder
Imports System.Text
Module Module1
Sub Main()
' Example list.
Dim vals As List(Of String) = New List(Of String)
vals.Add("thank")
vals.Add("you")
vals.Add("very")
vals.Add("much")
' Create StringBuilder.
' ... Append all items in For Each loop.
Dim builder As StringBuilder = New StringBuilder()
For Each val As String In vals
builder.Append(val).Append("|")
Next
' Convert to string.
Dim res = builder.ToString()
Console.WriteLine(res)
End Sub
End Module
Output
thank|you|very|much|
Note: You will need a newer version of .NET to have the ToList extension method.
Finally: The example demonstrates that the result List has the correct three elements.
VB.NET program that uses Split
Module Module1
Sub Main()
' Input string.
Dim value As String = "Dot-Net-Perls"
' Split on hyphen.
Dim arr() As String = value.Split("-")
' Convert to List.
Dim vals As List(Of String) = arr.ToList()
' Display each List element.
For Each val As String In vals
Console.WriteLine(val)
Next
End Sub
End Module
Output
Dot
Net
Perls