There are many times when I need to convert an array to a delimited string. Here is an easy way to do it using generics in .NET 2.0.

  Public Shared Function ConvertArrayToString(Of arrayType As {IEnumerable})(ByVal array As arrayType(), ByVal separator As Char) As String

 

      If Not IsValidArray(array) Then

        Throw New ArgumentNullException("array")

      End If

 

      If IsNothing(separator) Then

        Throw New ArgumentNullException("separator")

      End If

 

      Dim result As New System.Text.StringBuilder

 

      For Each arrayItem As arrayType In array

        If result.Length > 0 Then

          result.Append(separator)

        End If

 

        result.Append(arrayItem.ToString)

 

      Next

 

      Return result.ToString

 

  End Function

Tips By: David McCarter

This code and more like it can be found in the dotNetTips.Utility assembly on the CodePlex site: http://www.codeplex.com/dotNetTipsUtility


 
Comments are closed.