views:

19

answers:

1

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, 300 300, 400 400

So how to retrieve data from myfile.txt and later retrieve the string "100 100" from this chunk of data?

A: 
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

tadej5553
there is no syntax error but seemingly I cant get the string out of NSLog().
SilverTsuki
I did put myFile.txt in Resources folder. Am I correct?
SilverTsuki
Yes, you're correct.
tadej5553
Try NSLoging text string (if that's not what you have already done)
tadej5553
Oh I got it...thx
SilverTsuki