Latest Posts:

Reading a Text File line by line and Tokenizing each line in Objective C

Here's a confirmed working code of how to read a file line by line and thereafter, tokenizing it. 


    NSString *path = [[NSBundle mainBundlepathForResource:@"test2"ofType:@"txt"];
    NSString *string = [[NSString allocinitWithContentsOfFile:pathencoding:NSASCIIStringEncoding error:NULL];

    NSArray *lines = [string componentsSeparatedByString:@"\n"]; // each line, adjust character for line endings
    NSEnumerator *nse = [lines objectEnumerator];
    NSMutableArray *values = [NSMutableArray new];
    NSString *tmp;
    while(tmp = [nse nextObject])
    {
NSArray *chunks = [tmp componentsSeparatedByString@","];
NSEnumerator *nse2 = [chunks objectEnumerator];

NSString *tmp2;
while(tmp2 = [nse2 nextObject]){
NSLog(@"%@",tmp2);
}
NSLog(@"%@", tmp);
    }
Share on Google Plus

About Divya Prakash

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment