[NSString uppercaseString]
Returns an uppercased representation of the receiver.
- (NSString *)uppercaseString
Return Value
A string with each character from the receiver changed to its corresponding uppercase value.
Discussion of [NSString uppercaseString]
Case transformations aren’t guaranteed to be symmetrical or to produce strings of the same lengths as the originals. See
lowercaseString
for an example.Example of [NSString uppercaseString]
- (NSString *)sentenceCapitalizedString {
if (![self length]) {
return [NSString string];
}
NSString *uppercase = [[self substringToIndex:1] uppercaseString];
NSString *lowercase = [[self substringFromIndex:1] lowercaseString];
return [uppercase stringByAppendingString:lowercase];
}
Example of [NSString uppercaseString]
NSString *input = @"ÁlgeBra";
NSString *correctCase = [NSString stringWithFormat:@"%@%@",
[[input substringToIndex:1] uppercaseString],
[[input substringFromIndex:1] lowercaseString]];
NSString *result = [[[NSString alloc] initWithData:[correctCase dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES] encoding:NSASCIIStringEncoding] autorelease];
NSLog( @"%@", result );
Example of [NSString uppercaseString]
/* create a locale where diacritic marks are not considered important, e.g. US English */
NSLocale *locale = [[[NSLocale alloc] initWithLocaleIdentifier:@"en-US"] autorelease];
NSString *input = @"Àlter";
/* get first char */
NSString *firstChar = [input substringToIndex:1];
/* remove any diacritic mark */
NSString *folded = [firstChar stringByFoldingWithOptions:NSDiacriticInsensitiveSearch locale:locale];
/* create the new string */
NSString *result = [[folded uppercaseString] stringByAppendingString:[input substringFromIndex:1]];