Re: Splitting a string and assigning to variables
Re: Splitting a string and assigning to variables
- Subject: Re: Splitting a string and assigning to variables
- From: Jonathan Jackel <email@hidden>
- Date: Sun, 13 Jul 2003 17:30:46 -0400
On Sunday, July 13, 2003, at 04:00 PM, Matt Diephouse wrote:
Book *newBook = [[Book alloc] init];
NSArray *parts = [bookInfo componentsSeperatedByString:", "];
[newBook setTitle: [parts objectAtIndex:0]];
[newBook setAuthor: [parts objectAtIndex:1]];
[newBook setPublisher: [parts objectAtIndex: 2]];
I think that's a bit ugly though. I hope there's a better way. Is
there? Thanks.
The ugliness is the result of your data (bookInfo = @"Timeline, Michael
Crichton, Knopf") being ugly. If your data started as a dictionary you
could do this a little more elegantly. Arrays and strings don't know
as much about their contents as dictionaries. OTOH, dictionaries take
some effort to make in the first place.
Exactly what do you mean by "ugly" and "better" anyway?
Jonathan
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.