Hi All,
Is it possible or any library available for creating .csv file in ObjC ?
Thanks
Hi All,
Is it possible or any library available for creating .csv file in ObjC ?
Thanks
A CSV file is a text file of comma seperated values.
You could write an a routine that loops through values adding each one to a text file (or even add the values to a string?). After each field, add the ',' character. At the end of each row, add a new line. The first row can be the field titles.
E.g.
Year,Make,Model
1997,Ford,E350
2000,Mercury,Cougar
Here is a wikipedia article that describes what CSV is. I hope it can help.
CSV files are very simple.
If the data for each row is held in an array you could use -NSArray componentsJoinedByString:
to create a row for the CSV file. You'd also have to escape the text but that's shouldn't be too tricky. All that's left is appending the row to a file.
You may also like to read Writing a parser using NSScanner (a CSV parsing example), which explains how to read a CSV file.
NSArray has some functionality that can accomplish at least some of this (depending on whether or not you need to escape characters) pretty readily. Take a look at the componentsJoinedByString: method.
NSString has a partner method - componentsSeparatedByString: