Reads a delimited text file from disk. A delimited file is a specially formatted text file which stores spreadsheet or database-style information in a very simple format, with one row/record on each line, and each column/ field within that row/record separated by a delimiter character.
Each row that is read from the file is split into a specified number of columns based on the specified delimiter character. The columnar data is then converted to the appropriate data type, either numbers or strings, and added to an array that will eventually be returned. Empty or missing columns will be represented as empty elements (vbEmpty) in the array.
If each row contains a single column, then a one-dimensional array is returned. If any row contain more than one column, then a two-dimensional array will be returned, with the upper bounds of the second dimension corresponding to the maximum number of columns found in the file.
ANSI, UTF-8 and Unicode encoded text files are supported.
Rhino.ReadDelimitedFile (strFileName [, strDelimiter [, blnIgnoreEmptyRows [, blnTrimSpaces]]])
strFileName |
Required. String. The name of an existing delimited text file to read. |
strDelimiter |
Optional. String. The file's delimiter character. If omitted, a comma character will be used. |
blnIgnoreEmptyRows |
Optional. Boolean. If omitted or False (Default), then if an empty row is encountered in the file, then an empty element (vbEmpty) for each column will be added to the array. If True, then empty line will be skipped. |
blnTrimSpaces |
Optional. Boolean. If omitted or False (Default), then leading and trailing spaces for string elements in the will not be trimmed. If True, then leading and trailing spaces will be trimmed. |
Array |
Either a one or two dimensional array, depending in the input delimited file, if successful. |
Null |
On error. |
Dim strFile, arrData, i, j
strFile = Rhino.OpenFileName("Open", "Comma Delimited (*.csv)|*.csv|All Files (*.*)|*.*||")
If Not IsNull(strFile) Then
arrData = Rhino.ReadDelimitedFile(strFile)
If IsArray(arrData) Then
For i = 0 To UBound(arrData,1)
For j = 0 To UBound(arrData,2)
If IsEmpty(arrData(i,j)) Then
Call Rhino.Print("<empty>")
Else
Call Rhino.Print(arrData(i,j))
End If
Next
Next
End If
End If