SniffDelimiters
Returns a CSV dialect after run an analysis over a String variable or in the CSV/TSV file indicated in the .path
property of the configuration object.
Syntax
expression.SniffDelimiters
(confObject, [CSVstring] = vbNullString)
Parameters
Part | Description |
---|---|
confObject | Required. Identifier specifying a CSVparserConfig object variable. |
CSVstring | Optional. Identifier specifying a String Type variable. |
NumberOfRecords | Optional. Identifier specifying a Long Type variable. |
Returns value
Type: CSVdialect
- See also
- ParseConfig Property, CSVSniffer class.
Behavior
The parser will guess the delimiters in the CSV file only when the CSVstring
parameter is set to vbNullString
, otherwise the guessing occurs on the given string. Use the NumberOfRecords
parameter to define the number of records to be imported from the CSV file to detect delimiters, by default 10 records are imported.
⚠️Caution
Only the specified number of records will be used to guess the delimiters. The method is very accurate, but there is a risk of inaccuracy in some rare cases.
☕Example
Sub SniffInString()
Dim CSVint As CSVinterface
Dim CSVdata As String
Dim fPath As String
Set CSVint = New CSVinterface
fPath = Environ("USERPROFILE") & "\Desktop\Demo_100000records.csv"
With CSVint
CSVdata = .GetDataFromCSV(fPath)
Set .parseConfig.dialect = .SniffDelimiters(.parseConfig, CSVdata) 'Sniff delimiters and save to config object
End With
Set CSVint = Nothing
End Sub
Private Sub SniffInFile()
Dim CSVint As CSVinterface
Dim csvRecord As CSVArrayList
Set CSVint = New CSVinterface
With CSVint
.parseConfig.path = Environ("USERPROFILE") & "\Desktop\Demo_100000records.csv"
Set .parseConfig.dialect = .SniffDelimiters(.parseConfig) 'Sniff delimiters and save to config object
End With
Set CSVint = Nothing
End Sub