Is it possible to increase the letter, i.e. A + 1 = B In Objective-C?

I use this in C or C ++, that is:

myChar++; 

must increment a letter.

I try to do the same in Objective-C, except that I have NSString to start with (NSString is always just one letter). I tried converting NSString to char *, but this method is deprecated and other ways to achieve this do not work.

How do I convert NSString to char * - or is there a way to increment a character in objective-c without requiring char * somehow?

Thanks:)

+4
source share
2 answers
 // Get the first character as a UTF-16 (2-byte) character: unichar c = [string characterAtIndex:0]; // Increment as usual: c++; // And to turn it into a 1-character string again: [NSString stringWithCharacters:&c length:1]; 

Of course, this suggests that incrementing the Unicode character makes sense, which does for ASCII range characters, but probably not for others.

+12
source

How about NSString

 - (unichar)characterAtIndex:(NSUInteger)index; 

Will this work?

+1
source

Source: https://habr.com/ru/post/1334727/


All Articles