Swift CSV Mapper
The csv_mapper maps the content of a CSV (comma-separated value) file into an array of structures. The dataset type needs to be correctly defined to conform to the column names in the file. For instance, if the file contains columns: name age GPA then the type needs to have member elements like this:
type student {
file name;
file age;
file GPA;
}
If the file does not contain a header with column info, then the column names are assumed as column1, column2, etc.
Parameter | Meaning |
file | name of the CSV file to read mappings from. |
header | Whether the file has a line describing header info; default is |
true | |
skip | number of lines to skip at the beginning (after header line); default is 0. |
hdelim | Header field delimiter; default is the value of the |
delim | parameter |
delim | Content field delimiters; defaults are space, tab and comma |
Example:
student stus[] <csv_mapper;file="stu_list.txt">;
The above example would read a list of student info from file "stu_list.txt" and map them into a student array. By default, the file should contain a header line specifying the names of the columns. If stu_list.txt contains the following:
name,age,gpa
101-name.txt, 101-age.txt, 101-gpa.txt
name55.txt, age55.txt, age55.txt
q, r, s