VB.NET Convert String Array to String

String array illustration

String.Join combines many strings. You want to convert your String array into a String in your VB.NET program. There are a variety of ways you can accomplish this task, but the simplest way uses the String.Join function.

String Array Examples

This VB example program converts a String array into a single String.

Example

In this simple example program, we create a string array of three String literals on the managed heap. Next, we call String.Join: the first argument is the separator character, which is placed between elements. The second argument is the array reference itself.

Program that converts array to string [VB.NET]

Module Module1
    Sub Main()
	' Input array.
	Dim array() As String = {"Dot", "Net", "Perls"}

	' Convert to String data.
	Dim value As String = String.Join(".", array)

	' Write to screen.
	Console.WriteLine("[{0}]", value)
    End Sub
End Module

Output

[Dot.Net.Perls]

Result. We can see the result of the program is the String "Dot.Net.Perls". Please notice that no characters come before or after the String value. String.Join does not add the separator character after the final element.

Join String Function

Separator characters

Programming tip

If you need to have a separator character after the final element in the String, your best choice would probably be to use StringBuilder. Call the Append method on every element in the array, followed by an Append to add the separator. Usually, the trailing separator is not required in my experience.

StringBuilder Examples

Summary

The VB.NET programming language

We looked at the simplest way to convert a String array into a String. Though this approach is not the most flexible, it is useful in certain situations. If more flexibility is required, an imperative approach—looping and calling StringBuilder's Append function—could be used.

VB.NET Tutorials
.NET