NSScanner to find multiple occurrences of a prefix?
NSScanner to find multiple occurrences of a prefix?
- Subject: NSScanner to find multiple occurrences of a prefix?
- From: Devraj Mukherjee <email@hidden>
- Date: Tue, 13 Sep 2011 00:01:58 +1000
Hi all,
I am trying to use NSScanner to change camel cased strings into
underscore delimited strings, e.g featuredListingId to
featured_listing_id
I have worked our how to use NSScanner to achieve this, consider my
implementation (implemented as a NSString category)
- (NSString *) delimiterSeparatedWords
{
NSScanner *scanner = [NSScanner scannerWithString:self];
NSString *prefix = nil;
NSString *suffix = nil;
[scanner scanCharactersFromSet:[NSCharacterSet
lowercaseLetterCharacterSet] intoString:&prefix];
[scanner scanCharactersFromSet:[NSCharacterSet letterCharacterSet]
intoString:&suffix];
NSString *fieldNameString = [NSString stringWithFormat:@"%@_%@",
prefix, [suffix lowercaseString]];
return fieldNameString;
}
obviously it only addresses the first occurrence of a capital letter.
Can I ask NSScanner to keep looking for multiple occurrences?
Thanks for your time.
_______________________________________________
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