Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 985211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T05:07:55+00:00 2026-05-16T05:07:55+00:00

I am writing an iPhone application, which contains a function. It can convert the

  • 0

I am writing an iPhone application, which contains a function. It can convert the NSMutableArray to a CSV file. However, I don’t know how to do. Can anyone help me to do this? Thank you very much.

// —— Update —–

Thank you for everyone reply.

Actually, the array contains the objects of the elements, but I can convent it all to the array like the following (I guess it is more easy to do this).

The array is NSMutableArray *csvArray and the array contains data, like the following example.

csvArray[0] = First Name
csvArray[1] = Last Name
csvArray[2] = Phone
csvArray[3] = Tom
csvArray[4] = Chan
csvArray[5] = 123
csvArray[6] = Peter
csvArray[7] = Wong
csvArray[8] = 456
csvArray[9] = Mary's
csvArray[10] = Cho"w
csvArray[11] = 789...

There are 3 tabs in the begin of the array, which is first name, last name and the phone. For the data, it also contains the ” and , symbol. Therefore, I cannot just cut the array by the ‘,’ symbol.

The format I would like to output is the following

//---------------------------

First Name, Last Name, Phone  // <- it have the \r\n between each row of data
Tom, Chan, 123
Peter, Wong, 456
Mary's, Cho"w, 789 ...

//---------------------------
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T05:07:56+00:00Added an answer on May 16, 2026 at 5:07 am

    The CSV parser I wrote (http://github.com/davedelong/CHCSVParser) can parse CSV files into an NSArray of NSArrays (if you use the NSArray category included with the code), and I just added a method to the category to take one of those arrays and write it back to a CSV file.

    So if you have an NSArray of NSArrays, then you can write it to a CSV file like this:

    [myArray writeToCSVFile:myCSVFile atomically:YES];
    

    If will gracefully fail if you do not pass an NSArray of NSArrays.

    edit (prompted by @Aran’s comment to the question) any object inside the subarrays will have its -description method written to the CSV file. If you want to write a series of objects to the file, with various properties as the fields of the CSV row, then my wrapper requires that the properties be placed in an array, and then that array will make up the row.

    edit #2 I just updated my CSV parser to refactor the writing into it’s own class. You can now do the following:

    CHCSVWriter * csvWriter = [[CHCSVWriter alloc] initWithCSVFile:outputFile atomic:NO];
    NSInteger numberOfColumns = 3;
    for (NSInteger currentIndex = 0; currentIndex < [csvArray count]; currentIndex++) {
      id field = [csvArray objectAtIndex:currentIndex];
      [csvWriter writeField:field];
      if ((currentIndex % numberOfColumns) == (numberOfColumns - 1)) {
        [csvWriter writeLine];
      }
    }
    [csvWriter release];
    

    That will write your csvArray to the file whose path is outputFile, and the file will look like:

    First Name,Last Name,Phone
    Tom,Chan,123
    Peter,Wong,456
    Mary's,"Cho""w",789
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing an iPhone application which requires the user to enter several values
I'm writing an application which contains many tabs, and sometimes the number of tabs
I'm writing an iPhone application which uses UIView with a CAEAGLayer as its layer.
I'm writing iPhone/iPad application. I have UITextView in which I automatically appending text. How
I'm currently writing an iPhone application which gets some data from the user and
I'm writing an iPhone application which needs to have an option to call our
I'm writing an iPhone application which you need to authenticate at the beginning. Therefore
I'm writing an iphone application that pulls xlsx file from the server, manipulates with
Iam writing an iPhone application which is posting a few queries to facebook via
I am writing an iPhone application in which user sign in, and than read

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.