Home
VB.NET
Convert String Array to String
This page was last reviewed on Dec 4, 2023.
Dot Net Perls
Convert array, String. The String.Join function in VB.NET combines many strings. With it we can convert a String array into a String.
Conversion info. There are a variety of ways you can convert a string array into a string. But the simplest way uses the String.Join function.
Array
Example. Here we create a string array of 3 Strings. We call String.Join. The first argument is the separator character, which is placed between elements. The second argument is the array.
Result We can see the result of the program is joined together by a comma character.
Note No characters come before or after the String value. String.Join does not add the separator character after the final element.
String.Join
Module Module1 Sub Main() ' Input array. Dim array() As String = {"Dog", "Cat", "Python"} ' Convert to String data. Dim value As String = String.Join(",", array) ' Write to screen. Console.WriteLine("[{0}]", value) End Sub End Module
[Dog,Cat,Python]
Separator note. If you need to have a separator character after the final element in the String, your best choice would probably be to use StringBuilder.
Info Call the Append method on every element in the array, followed by an Append to add the separator.
However The trailing separator is usually not required in my experience. It sometimes even causes problems.
StringBuilder
A summary. We looked at the simplest way to convert a String array into a String in the VB.NET programming language. This approach is not the most flexible. But it is useful in certain situations.
Dot Net Perls is a collection of tested code examples. Pages are continually updated to stay current, with code correctness a top priority.
Sam Allen is passionate about computer languages. In the past, his work has been recommended by Apple and Microsoft and he has studied computers at a selective university in the United States.
This page was last updated on Dec 4, 2023 (edit).
Home
Changes
© 2007-2024 Sam Allen.