Re: NSString camel case
Re: NSString camel case
- Subject: Re: NSString camel case
- From: Dave Keck <email@hidden>
- Date: Sat, 11 Apr 2009 20:46:38 -1000
Cocoa has always been lacking in the RegEx department (at least the
'built-in' Cocoa classes, there's a bunch of third-party regex
frameworks), especially when compared to languages like Python. Since
your situation isn't very complex, I would just use the bread-n-butter
string APIs:
NSString *originalString = @"everything_else_is_my_name";
NSArray *originalStringComponents,
*resultingComponents;
NSMutableString *result = [NSMutableString string];
originalStringComponents = [originalString
componentsSeparatedByString: @"_"];
for (NSString *currentStringComponent in originalStringComponents)
[result appendString: [NSString stringWithFormat: @"%@%@",
[currentStringComponent capitalizedString],
(currentStringComponent != [originalStringComponents lastObject] ? @"
" : @"")]];
NSLog(@"%@", result);
(Better-formatted version here: http://pastie.org/444173).
Note that this snippet isn't incredibly efficient, but should get the
point across...
David
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden