Add method to cap JUST the first letter

This commit is contained in:
Gregory John Casamento 2023-01-17 03:50:37 -05:00
parent ce36666d79
commit 3a0f7d8882
2 changed files with 14 additions and 0 deletions

View file

@ -7,6 +7,7 @@
@interface NSString (Methods)
- (NSString *) capitalizedFirstCharacterString;
- (NSString *) splitCamelCaseString;
@end

View file

@ -7,6 +7,19 @@
@implementation NSString (Methods)
// Return a string with the first character capitalized
- (NSString *) capitalizedFirstCharacterString
{
if ([self length] == 0)
{
return self;
}
return [NSString stringWithFormat: @"%@%@",
[[self substringToIndex: 1] uppercaseString],
[self substringFromIndex: 1]];
}
// Split a camel case string into a string with spaces
// e.g. "camelCaseString" becomes "camel Case String"
- (NSString *) splitCamelCaseString