Skip to content

Instantly share code, notes, and snippets.

@fredgdaley2
Last active August 29, 2015 14:08
Show Gist options
  • Save fredgdaley2/da545e0c0f59a2aa9036 to your computer and use it in GitHub Desktop.
Save fredgdaley2/da545e0c0f59a2aa9036 to your computer and use it in GitHub Desktop.
Get string value prepared for csv file. #fregdaley2 #extension #csv
<Extension()> _
Public Function ToCsvValue(ByVal source As Object, Optional ByVal addDelimiter As Boolean = True) As String
Dim csvValue As String
If source Is Nothing Then
csvValue = ""
Else
csvValue = CStr(source).Trim
End If
If addDelimiter Then
Return If(csvValue.IndexOf(",") > -1, String.Format("""{0}"",", csvValue), String.Format("{0},", csvValue))
Else
Return If(csvValue.IndexOf(",") > -1, String.Format("""{0}""", csvValue), String.Format("{0}", csvValue))
End If
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment