诀窍是不使用该FieldQuoted
属性,而是应用自定义FieldConverter
来删除引号。
Public Class MyQuotedStringConverter
Inherits ConverterBase
Public Overrides Function StringToField(from As String) As Object
' StringToField() is used by import. The 'from' parameter will contain all the text between the comma delimiters (including all quotes)
Dim result As String = from
' remove the first and last quotes
If result IsNot Nothing Then
If result.StartsWith("""") Then
result = result.SubString(1)
End If
If result.EndsWith("""") Then
result = result.SubString(0, result.Length - 1)
End If
End If
Return result
End Function
Public Overrides Function FieldToString(fieldValue As Object) As String
' FieldToString is used by export
Return fieldValue.ToString()
End Function
End Class
并更改任何问题字段以使用转换器。例如
<DelimitedRecord(","), IgnoreFirst(1)>
Public Class yyy
<FieldConverter(GetType(MyQuotedStringConverter))> _
Public IDAs String
<FieldConverter(GetType(MyQuotedStringConverter))> _
Public AccidentDescr As String
<FieldQuoted()> <FieldConverter(ConverterKind.Date, "yyyy-MM-dd")> _
Public DOI As DateTime