Note that there are some explanatory texts on larger screens.

plurals
  1. POProblems handling Carriage Returns while writing CSV files
    text
    copied!<p>I need to save NSStrings from an array into a .csv file in my documents directory, which is not a problem, but I don't know how to handle the carriage return.. I specify that I want to apply a carriage return every 8 cells and this happens correctly. However when it comes to write the actual CSV file an extra unwanted comma is added after the carriage return! This is the incriminated line:</p> <pre><code>NSString *ArrayConvertedIntoStringFINAL = [FinalStringsArrayWithCarriageReturns componentsJoinedByString:@","]; </code></pre> <p>How can I tell the compiler not to apply a comma after a carriage return?</p> <p>Here is the complete code. Thanks guys!</p> <pre><code>//Add a Carriage Return symbol every N objects (every FREQUENCY) int FREQUENCY = 8; //Define String WithCarriageReturns NSMutableArray *FinalStringsArrayWithCarriageReturns = [[NSMutableArray alloc] initWithCapacity:0]; for (int i = 1; i &lt;= [FinalStringsArray count]; i++) { NSString *readValue = [FinalStringsArray objectAtIndex:i-1]; //Add objects to the final string [FinalStringsArrayWithCarriageReturns addObject:readValue]; if ( (i % FREQUENCY) == 0) //Number is multiple of N { //Every multiple of N add the Carriage Return symbol [FinalStringsArrayWithCarriageReturns addObject:CarriageReturn]; } } NSLog(@"+2+Broken down array strings: %@",FinalStringsArrayWithCarriageReturns); //PROBLEM! A comma is added after the Carriage Return //Convert Array into String NSString *ArrayConvertedIntoStringFINAL = [FinalStringsArrayWithCarriageReturns componentsJoinedByString:@","]; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload