user426795
user426795

Reputation: 11683

how to convert lower case character to upper case?

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

Answers (3)

Tony
Tony

Reputation: 158

unichar c = [[myString lowercaseString] characterAtIndex:0];

Try this.

Upvotes: 1

Erik van der Neut
Erik van der Neut

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

Max Seelemann
Max Seelemann

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

Related Questions