2

Is it possible or any library available for creating .csv file in ObjC ?

Thanks

3

4 Answers 4

3

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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.

1 Comment

While CSV can be simple, in general they are not. You must properly deal with column values containing the column separator (comma) and newlines.
1

Take a look at chcsvparser.

Comments

0

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:

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.