我需要将数组中的 NSStrings 保存到我的文档目录中的 .csv 文件中,这不是问题,但我不知道如何处理回车。我指定我想每 8 次应用回车细胞,这会正确发生。但是,在编写实际的 CSV 文件时,回车后会添加一个多余的逗号!这是有罪的行:
NSString *ArrayConvertedIntoStringFINAL = [FinalStringsArrayWithCarriageReturns componentsJoinedByString:@","];
如何告诉编译器在回车后不要使用逗号?
这是完整的代码。多谢你们!
//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 <= [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:@","];