NSData to ...?

Moderator
Posts: 916
Joined: 2002.10
Post: #1
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 -_-)
Quote this message in a reply
Moderator
Posts: 508
Joined: 2002.09
Post: #2
use NSString's stringWithContentsOfFile, and then use componentsSeparatedByString:@" " to get an array of all of those things.

"When you dream, there are no rules..."
Quote this message in a reply
Moderator
Posts: 916
Joined: 2002.10
Post: #3
Taxxodium Wrote:use NSString's stringWithContentsOfFile, and then use componentsSeparatedByString:@" " to get an array of all of those things.
*licks*

thank you! ^_^
Quote this message in a reply
Moderator
Posts: 916
Joined: 2002.10
Post: #4
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?
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #5
NSScanner is your friend.
Quote this message in a reply
Moderator
Posts: 916
Joined: 2002.10
Post: #6
OneSadCookie Wrote:NSScanner is your friend.
aha, just what I was looking for!
Quote this message in a reply
Post Reply