Re: Parsing NSString
Re: Parsing NSString
- Subject: Re: Parsing NSString
- From: Simon Boissonnault <email@hidden>
- Date: Tue, 25 Jan 2005 04:56:00 -0500
Does anyone know of a quick & easy way to parse an NSString containing
text seperated by white space (i.e. command-line args) into an
NSArray?
-Michael
Parsing is not a simple task.
And it depends on the kind of string you are expecting from the user.
Will the string contain keywords ? Numbers ? Arithmetic expressions ?
If you are only expecting keywords separated by spaces, then you could
just loop through the entire string, and everytime you bump into a
space, you know you have a keyword, make a NSString with it and store
it into a NSMutableArray. Then you would validate every keyword (check
if they make sense for your app) by comparing with some sort of array
of legal keywords. Then, the harder part is to associate the keywords
with the corresponding operations.
If your parser needs to cope with arthmetic expressions, you'll
probably want to implement RPN (Reverse Polish Notation).
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden