Questions And Answers

More Tutorials

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
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


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:

101-name.txt, 101-age.txt, 101-gpa.txt
name55.txt, age55.txt, age55.txt
q, r, s


In this page (written and validated by ) you learned about Swift CSV Mapper . What's Next? If you are interested in completing Swift tutorial, your next topic will be learning about: Swift External Mapper.

Incorrect info or code snippet? We take very seriously the accuracy of the information provided on our website. We also make sure to test all snippets and examples provided for each section. If you find any incorrect information, please send us an email about the issue:

Share On:

Mockstacks was launched to help beginners learn programming languages; the site is optimized with no Ads as, Ads might slow down the performance. We also don't track any personal information; we also don't collect any kind of data unless the user provided us a corrected information. Almost all examples have been tested. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. By using, you agree to have read and accepted our terms of use, cookies and privacy policy.