In my personal of Iphone development project I need to retrieve data from plain txt file, afterwards using delimiter to separate data in the way I want. It's my sample data:
100 100, 200 200, 3开发者_JAVA技巧00 300, 400 400
So how to retrieve data from myfile.txt
and later retrieve the string "100 100
" from this chunk of data?
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"myFile" ofType:@"txt"];
NSString *text = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:NULL];
This is for getting the contents of the file. To seperate different pieces of data use this:
NSArray *items = [text componentsSeparatedByString:@", "];
I hope this is helpful
精彩评论