Skip to content

Instantly share code, notes, and snippets.

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 ScottHutchinson/08b47b88bf41ccc7a4c1f73463abb555 to your computer and use it in GitHub Desktop.
Save ScottHutchinson/08b47b88bf41ccc7a4c1f73463abb555 to your computer and use it in GitHub Desktop.
SplitCommaDelimitedLineWithQuotedValues function
' hutch: 10/04/18. Added this function to enable an import file to contain a DX file path that includes commas.
Public Shared Function SplitCommaDelimitedLineWithQuotedValues(ByVal value As String, ByVal delimiter As Char) As String()
' Split using comma as the delimiter, but ignoring commas inside single quotes (')
Dim values = Regex.Split(value, ",(?!(?=[^']*'[^']*(?:'[^']*'[^']*)*$))")
' Trim spaces and single quotes from each item in values.
Dim ret = values.Select(Function(x) x.Trim(New Char() {" "c, "'"c})).ToArray()
Return ret
End Function
' Example call: Dim token As String() = SplitCommaDelimitedLineWithQuotedValues(line, ","c) 'token may start with space
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment