Convert NSString to unichar in iOS

I saw stackoverflow questions that convert unichar to NSString, but now I would like to do the opposite.

How can I do it?

Need to be guided .. Thanks

For example, I have an array of strings: [@"o",@"p",@"q"];

These are the lines inside. How to convert it back to unichar?

+7
source share
2 answers

The following will work until the first character is actually two matched characters (in other words, if the character has no Unicode value greater than \ UFFFF):

 unichar ch = [someString characterAtIndex:0]; 
+9
source

You can convert it to a buffer in NSData :

 if ([string canBeConvertedToEncoding:NSUnicodeStringEncoding]) { NSData * data = [string dataUsingEncoding:NSUnicodeStringEncoding]; const unichar* const ptr = (const unichar*)data.bytes; ... } 
+1
source

All Articles