I have an array composed by other array:
example my array with two arrays inside:
myArray = [(element1, element2, element3)],[(element4,element5,element6)] this is only an example to show that myArray have two arrays (these elements are string)
now I want write in a txt file these elements in this way:
element1#element2#element3;element4#element5#element6;
what is the code to create this string to write in txt file?
NSMutableString *printString = [NSMutableString stringWithString:@""];
for(i=0;i<[myArray count];i++)
{
for (NSString element in [myArray objectAtIndex:i])
{
[printString appendString:[NSString stringWithFormat:@"%@#",element] ];
}
[printString appendString:@";"];
}
//CREATE FILE
NSError *error;
// Create file manager
//NSFileManager *fileMgr = [NSFileManager defaultManager];
NSString *documentsDirectory = [NSHomeDirectory()
stringByAppendingPathComponent:@"Documents"];
NSString *filePath = [documentsDirectory
stringByAppendingPathComponent:@"fileArray.txt"];
NSLog(@"string to write:%@",printString);
// Write to the file
[printString writeToFile:filePath atomically:YES
encoding:NSUTF8StringEncoding error:&error];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With