I'm looking for a simple, efficient way to convert strings in CamelCase to underscore notation (i.e., MyClassName -> my_class_name) and back again in Objective C.
My current solution involves lots of
Chris's suggestion of RegexKitLite is good. It's an excellent toolkit, but this could be done pretty easily with NSScanner. Use
-scanCharactersFromSet:intoString: alternating between
+lowercaseLetterCharacterSet. For going back, you'd use
-scanUpToCharactersFromSet: instead, using a character set with just an underscore in it.