views:

31

answers:

1
  1. I have a string employeeName, what's the easiest way to change this to 'Employee Name' in cocoa?

  2. Also how would I just extract the first word in the above?

+1  A: 

Create an NSScanner for the string, then tell it to scan up until an uppercase letter. If you want to scan more than one word, then scan one word at a time multiple times, until you run out of words.

I believe that NSScanner won't scan any further once you're at an uppercase letter, so you'll need to scan the uppercase letter(s) into one string, then scan everything up to the next run of them into another string, then join those two strings.

Peter Hosey