Created
October 4, 2018 18:01
-
-
Save ScottHutchinson/08b47b88bf41ccc7a4c1f73463abb555 to your computer and use it in GitHub Desktop.
SplitCommaDelimitedLineWithQuotedValues function
This file contains hidden or 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
' 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