I have an unsigned char* array1
with values >127 && <255
.
And I want to display it in UITextView* MyTextView
and then read it back from UITextView
to another unsigned char* array2
. As result values in array1
should equal to values in array2
.
I understand that text property of UITextView
is NSString
object with UTF16 encoding inside.
And my codes greater then 127 are two-bite in UTF16 encoding. So if I want to display my array1 and receive read it back to array2 I need to proceed with steps:
- convert my one-byte char to two-byte with replacement of each char with mapping UTF18(as result my array1 will become twice bigger).
- convert my array1 to NSString using UTF16 encoding;
- convert my NSString back to array2 with UTF16encoding.
- convert each two-byte sequence to one byte char of array2.
How I can convert my non-ASCII chars >127 to UTF16? Use mapping?
Code:
UITextView* MyTextView;//assume this exists
unsigned char array1[] = {130,150,250};
unsigned char *array2 = malloc(4);
MyTextView.text = [NSString stringWithCString:array1 encoding: NSUTF16StringEncoding];
[MyTextView.text getCString:array2 length:MyTextView.text encoding:NSUTF8StringEncoding];
As result values of array1
and array2
differs.
Please help to understand and convert my chars >127 to UTF16.