开发者

Retrieve data from a plain file (Iphone development)

开发者 https://www.devze.com 2023-01-23 07:27 出处:网络
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.

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

精彩评论

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