Skip to content

Instantly share code, notes, and snippets.

@binki
Last active October 22, 2019 15:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save binki/f627fd3167069ba9554f8844c2f424d8 to your computer and use it in GitHub Desktop.
Save binki/f627fd3167069ba9554f8844c2f424d8 to your computer and use it in GitHub Desktop.
Example of quoting CSV in VB.Net
This is some text, but it is free-form and might have double quotes (") in it Text with a newline 23

The output imported into Excel: imported to Excel

Imports System
Public Module Program
Public Sub Main()
Dim num = 23
Dim value = "This is some text, but it is free-form and might have double quotes ("") in it"
Dim value2 = "Text with a" & Environment.NewLine & "newline"
Console.WriteLine(QuoteCsvField(value) & "," & QuoteCsvField(value2) &"," & num)
End Sub
Public Function QuoteCsvField(value As String) As String
Return """" & value.Replace("""", """""") & """"
End Function
End Module
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment