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 6365653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:19:12+00:00 2026-05-25T00:19:12+00:00

I am able to get the CSV file data into array, but when it

  • 0

I am able to get the CSV file data into array, but when it is taking the data of next line, it is taking a \n character. how to remove the \n character.

My CSV FILE contents are:

Hello,World,hhh
nnn,sss,eee

I am getting the output as

2011-08-24 15:29:16.069 CSVParsing[1030:903] (
    Hello
)
2011-08-24 15:29:16.072 CSVParsing[1030:903] (
    World
)
2011-08-24 15:29:16.075 CSVParsing[1030:903] (
    "hhh\nnnn"
)
2011-08-24 15:29:16.076 CSVParsing[1030:903] (
    sss
)
2011-08-24 15:29:16.077 CSVParsing[1030:903] (
    "eee\n"
)

How to overcome this problem

Following is the code i am Using.

{
NSString *pathToFile =[[NSBundle mainBundle] pathForResource:@”hw” ofType: @”csv”];
NSError *error;

NSString *fileString = [NSString stringWithContentsOfFile:pathToFile encoding:NSUTF8StringEncoding error:&error];
if (!fileString) {
    NSLog(@"Error reading file.");
} 
scanner = [NSScanner scannerWithString:fileString];    
[scanner setCharactersToBeSkipped:[NSCharacterSet characterSetWithCharactersInString:@","]];


while ([scanner scanUpToString:@"," intoString:&pathToFile]  )
{
    arrayItems = [pathToFile componentsSeparatedByString:@","];


    NSLog(@"%@",arrayItems);

}

}

  • 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-25T00:19:13+00:00Added an answer on May 25, 2026 at 12:19 am

    You just scan over the end of the line, treating newline just as another character. You could fix this by wrapping your scanner code into enumerateLinesUsingBlock:, which is an NSString method.

    But really, this is then not a complete parser. You might have to handle a lot of special cases. Maybe you should look around, there is for example this one:

    Where can I find a CSV to NSArray parser for Objective-C?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Has anyone been able to get a variable record length text file (CSV) into
Scenario I want to parse a large CSV file and inserts data into the
I am trying to download a .csv file into an array and then parse
I'm able to get cells to format as Dates, but I've been unable to
I am trying to dump the contents of a table to a csv file
I'm importing some data from a CSV file, and numbers that are larger than
I am trying to do 2 output data from mysql to a csv file.
I have a stored procedure called sp_BulkInsert that inserts one .csv file into my
I have a large data coming from a csv file which looks something like
I get an input CSV file that I have to upload to my oracle

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.