Reputation: 109
I, I'm writing an application that has to read the content of txt. this txt is such a property file with a list formatted in this way:
1|Chapter 1|30
2|Chapter AA|7
3|Story of the United States|13
........
keys are separated by "|".
I googled a lot hoping to find any "pragmatically solution" but nothing... how can I read these informations and set many objects like:
for NSInterger *nChapter = the first element
for NSString *title = the second element
for NSInteger *nOfPages = the last element ?
Upvotes: 0
Views: 89
Reputation:
Only if you read NSString's class reference:
NSString *str = [NSString stringWithContentsOfFile:@"file.txt"];
NSArray *rows = [str componentsSeparatedByString:@"\n"];
for (NSString *row in rows)
{
NSArray *fields = [row componentsSeparatedByString:@"|"];
NSInteger nChapter = [[fields objectAtIndex:0] intValue];
NSString *title = [fields objectAtIndex:1];
// process them in here
}
Upvotes: 0
Reputation: 3588
NSString's - (NSArray *)componentsSeparatedByString:(NSString *)separator
could be your best friend.
Upvotes: 1