id: text.csv title: Text.CSV
Text.CSV is a CSV (Comma Separated Values) file parser. CSV files are a popular format for exchanging data between applications, as they are simple, flexible, and can be easily generated or consumed by various software programs.
We will explore the CSV file format in depth, and learn how to use the Text.CSV to load and manipulate CSV files in BlitzMax applications.
CSV files are plain text files that store tabular data, making them suitable for representing spreadsheet-like
structures. Each row in a CSV file corresponds to a single line of text, and columns within a row are separated by
a delimiter, which is typically a comma (,) or a tab (\t). CSV files can store various types of data, such as
numbers, text, and dates, and they can accommodate both simple and complex data structures.
There are several reasons why one might choose to use the CSV file format over other formats:
To create a valid CSV file that can be loaded into Text.CSV, you should follow these basic rules:
"John Doe", 25, "123 Main St, Apt 4B" has the address field quoted because it contains
a comma. To represent a double quote within a quoted field, use two double quotes together, like "". For example,
"He said, ""Hello"""You'll need to create an instance of the TCsvParser type, and then use its various methods to interact with the CSV data. The parser accepts input streams in UTF-8 format.
Here is a basic example of how to use the module:
SuperStrict
Framework BRL.StandardIO
Import Text.CSV
Local options:TCsvOptions = New TCsvOptions
options.delimiter = ","
Local parser:TCsvParser = TCsvParser.Parse("path/to/your/csvfile.csv", options)
While parser.NextRow() = ECsvStatus.row
Local row:TCsvRow = parser.GetRow()
Print row.GetValue("column_name")
Wend
parser.Free()
| Type | Description |
|---|---|
| TCsvParser | Csv Parser |
| TCsvOptions | Options for customising the parser. |
| TCsvRow | A Csv Row. |
| TCsvHeader | A csv header. |
| Struct | Description |
|---|---|
| SCsvColumn | A csv column. |