Created
April 5, 2011 06:44
-
-
Save jesperbjensen/903136 to your computer and use it in GitHub Desktop.
A nice extension method that lets you comma seperate anything
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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