Last active
August 29, 2015 14:08
-
-
Save fredgdaley2/da545e0c0f59a2aa9036 to your computer and use it in GitHub Desktop.
Get string value prepared for csv file. #fregdaley2 #extension #csv
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 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