1

I'm working on an application where the user's name is printed in a UILabel. I'm calling NSString's capitalizedString method on the string that's being fed to the UILabel (so that the user's first, middle, and last names are capitalized). Here's some code for reference:

cell.textLabel.text = [theUsersName capitalizedString];

My problem is that I've encountered a user with Roman numerals in his/her name. The Roman numerals are being capitalized like so: 'Iii'.

My question is how can I detect Roman numerals and put them in all caps (III), while still maintaining the capitalizedString functionality. Is a regex my only option?

EDIT

I've decided to go with Regular Expressions to solve this problem. However I'm having trouble implementing. I'm not too familiar with using NSRegularExpression, so could someone help out with the algorithm for solving this problem and point to some useful methods?

hgwhittle
  • 9,316
  • 6
  • 48
  • 60
  • 6
    You probably can't in the general case - `Vi` is a name and `VI` is a number, right? `Li`, too. Does your program handle names with internal capitalization? My wife's name is like that, and she hates programs like yours that wreck her correctly-entered capitalization. – Carl Norum Aug 02 '13 at 14:51
  • 4
    Regex? What's wrong with a regex? ([link](http://stackoverflow.com/questions/267399/how-do-you-match-only-valid-roman-numerals-with-a-regular-expression)) – Sergey Kalinichenko Aug 02 '13 at 14:52
  • 1
    @CarlNorum - Yes, you're right. I hadn't thought of that. – hgwhittle Aug 02 '13 at 14:53
  • @dasblinkenlight - I'm lazy. Ha but I'll pursue regex if necessary. Thanks for the link! – hgwhittle Aug 02 '13 at 14:54
  • 1
    @hw731 SO's search is for the lazy (I mean, smart) people who don't want to repeat someone else's successful effort just for the sake of repeating it. The answer has a perfectly valid regex. Apply it in case-sensitive mode, find places that must not be touched, capitalize the string, and copy the numeric parts back from the original. That's what a lazy person would do, right? – Sergey Kalinichenko Aug 02 '13 at 14:58
  • @dasblinkenlight - You make a good point. Someone else's regex it is! – hgwhittle Aug 02 '13 at 15:05

0 Answers0