• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Reliable way to capitalize camel-case strings?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Reliable way to capitalize camel-case strings?


  • Subject: Re: Reliable way to capitalize camel-case strings?
  • From: Rob Rix <email@hidden>
  • Date: Mon, 22 Dec 2008 07:22:18 -0500

I’m interested to know if there’s a better way to do this than the ugly way I’ve been using, too:

NSString *first = [string substringWithRange: NSMakeRange(0, 1)];
NSString *rest = [string substringFromIndex: 1];
NSString *result = [[first uppercaseString] stringByAppendingString: rest];


Rob

On 22-Dec-08, at 6:23 AM, 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.

Since the KVC mechanism must be doing this a lot, I wondered if there was an API I'm overlooking.


thanks,

Graham


_______________________________________________

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

_______________________________________________

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


  • Follow-Ups:
    • Re: Reliable way to capitalize camel-case strings? [SOLVED]
      • From: Graham Cox <email@hidden>
References: 
 >Reliable way to capitalize camel-case strings? (From: Graham Cox <email@hidden>)

  • Prev by Date: Re: NSCalendar/NSDate - generating all months/days in a year
  • Next by Date: Re: NSCalendar/NSDate - generating all months/days in a year
  • Previous by thread: Reliable way to capitalize camel-case strings?
  • Next by thread: Re: Reliable way to capitalize camel-case strings? [SOLVED]
  • Index(es):
    • Date
    • Thread