CamelCase in Objective-C
Example for versions
gcc 3.4.5 (Objective-C)
#import <Foundation/Foundation.h>
NSString *camelCase(NSString *s) {
return [[[s capitalizedString] componentsSeparatedByCharactersInSet:[[NSCharacterSet characterSetWithCharactersInString:@"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"] invertedSet]] componentsJoinedByString:@""];
}
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSLog(@"%@", camelCase(@"Test Example One"));
NSLog(@"%@", camelCase(@"exampleTwo "));
NSLog(@"%@", camelCase(@"!!! is_this_3RD EXAMPLE?.."));
[pool drain];
return 0;
}
Comments
]]>blog comments powered by Disqus
]]>