Re: Reliable way to capitalize camel-case strings?
Re: Reliable way to capitalize camel-case strings?
- Subject: Re: Reliable way to capitalize camel-case strings?
- From: Gregory Weston <email@hidden>
- Date: Mon, 22 Dec 2008 08:44:12 -0500
Graham Cox wrote:
In my app I need a way to generate the name of a method based on a
property key. If the key is, e.g. -scaleFactor, and the generated
method name needs to be -displayNameForScaleFactor, how can I reliably
turn "scaleFactor" into "ScaleFactor"? I tried [NSString
capitalizedString] but I get "Scalefactor". Obviously capitalizing an
ASCII string is trivial but I'm not sure that I can assume that
encoding for method names.
There are probably more efficient ways, but brute force should work:
NSRange fc = NSMakeRange(0,1);
NSString* s2 = [[s1 substringWithRange:fc] uppercaseString];
NSString* s3 = [s1 stringByReplacingCharactersInRange:fc withString:s2];
If you need to support pre-10.5, I guess you'll need to make a
mutable string for the replacement step.
_______________________________________________
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