iDevGames Forums
NSData to ...? - Printable Version

+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Game Programming Fundamentals (/forum-7.html)
+--- Thread: NSData to ...? (/thread-4674.html)



NSData to ...? - skyhawk - Dec 27, 2005 01:58 PM

I have an NSString path to a text file (presumably)
I would like to be able to parse this file, the best I can gather is:
Code:
NSFileWrapper *fwap = [[NSFileWrapper alloc] initWithPath:afile];
NSData *tehdata = [fwap serializedRepresentation];

where do I go from here to convert it into something more readable. Here is actually what is in the file:
Code:
B1 264 5.993 100
B1 266 125.76 200
B4 264 12.36 100
and so on.

any help is appreciated. (Using Objective-C for those not able to quickly pick up on that -_-)


NSData to ...? - Taxxodium - Dec 27, 2005 02:04 PM

use NSString's stringWithContentsOfFile, and then use componentsSeparatedByString:@" " to get an array of all of those things.


NSData to ...? - skyhawk - Dec 27, 2005 02:08 PM

Taxxodium Wrote:use NSString's stringWithContentsOfFile, and then use componentsSeparatedByString:@" " to get an array of all of those things.
*licks*

thank you! ^_^


NSData to ...? - skyhawk - Dec 29, 2005 03:32 PM

yay for follow up (yes yes, I am ever so silly for wanting to use cocoa for text parsing):
M'k, I have a line of stuff:
Code:
8B,1 10.96 150.86 59 584 4111
all stuck in a single NSString.
I want to first read up to a letter. so it would take all non letter up to the first letter then I can stick that into a string. then I move on (maybe delete what I have read so far) and then read up to the comma. then up to the white space, then up to next white space, and so on.

Anybody have a good pointer as to how I can start this?


NSData to ...? - OneSadCookie - Dec 29, 2005 03:53 PM

NSScanner is your friend.


NSData to ...? - skyhawk - Dec 29, 2005 04:24 PM

OneSadCookie Wrote:NSScanner is your friend.
aha, just what I was looking for!