Skip to content

Instantly share code, notes, and snippets.

@jesperbjensen
Created April 5, 2011 06:44
Show Gist options
  • Save jesperbjensen/903136 to your computer and use it in GitHub Desktop.
Save jesperbjensen/903136 to your computer and use it in GitHub Desktop.
A nice extension method that lets you comma seperate anything
<Extension()> _
Public Function CommaSeperate(Of T)(ByVal lstList As IEnumerable(Of T), ByVal delFunction As Func(Of T, String), ByVal strDelimiter As String) As String
Dim builder As New StringBuilder
For Each item As T In lstList
If delFunction IsNot Nothing Then
builder.Append(delFunction(item) & strDelimiter)
Else
builder.Append(item.ToString() & strDelimiter)
End If
Next
Return builder.ToString().Trim().TrimEnd(strDelimiter)
End Function
<Extension()> _
Public Function CommaSeperate(Of T)(ByVal lstList As IEnumerable(Of T), ByVal delFunction As Func(Of T, String)) As String
Return CommaSeperate(lstList, delFunction, ",")
End Function
<Extension()> _
Public Function CommaSeperate(Of T)(ByVal lstList As IEnumerable(Of T)) As String
Return CommaSeperate(lstList, Nothing, ",")
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment