开发者

Retrieve data from a plain file (Iphone development)

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜