Reputation: 11683
unichar c;
c = [myString characterAtIndex:0];
unichar catchcar = [c lowercaseString];
error : invalid reciever type unicar.
I know lowercaseString
is used to covert String not character. Is there any solution?
Upvotes: 1
Views: 10148
Reputation: 158
unichar c = [[myString lowercaseString] characterAtIndex:0];
Try this.
Upvotes: 1
Reputation: 2245
The simplest solution for converting case on a single character is to just use the C functions tolower
and toupper
. Using the code example from the question and rewriting that would give this for conversion to lowercase:
#import <ctype.h>
unichar catchcar = tolower([myString characterAtIndex:0]);
No need to do anything complicated with the NSString API. And no need to make the whole string lowercase first either.
Hope this helps,
Erik
Upvotes: 2
Reputation: 9364
you could do the following:
unichar catchcar = [[myString lowercaseString] characterAtIndex: 0];
If you have a a character only, do the following:
// given unichar c
unichar catchcar = [[[NSString stringWithCharacters:&c length:1] lowercaseString] characterAtIndex: 0];
Upvotes: 8