S
S
Sergey Krivosheev2017-10-30 16:57:58
Objective-C
Sergey Krivosheev, 2017-10-30 16:57:58

Objective-c qr-code encoded cp1251, how to convert to UFT8?

Good afternoon.
I am developing an application with the ability to read qr-code. Faced a problem when characters in cp1251 encoding were encoded in ar-code.
I take the string from ar-code like this

NSString *scannedResult = [(AVMetadataMachineReadableCodeObject *)current stringValue];

but it already contains not the correct encoding of Russian characters. After that I try to translate the string into NSData and then into a string with UTF8. But the NSData = nil object, it feels like the variable is already stored in UTF8 format but with broken characters. Because when I decode this UTF8-encoded string into bytes, the array is filled with bytes.
Tell me how you can
1. Determine in what encoding the characters in the string (because when I read a string in UTF8 there are no problems)
2. If the characters are in cp1251, re-encode it into UTF8
NSData *dt = [scannedResult dataUsingEncoding:NSWindowsCP1251StringEncoding];//dt = nil
            scannedResult = [[NSString alloc] initWithData:dt encoding:NSUTF8StringEncoding];


NSData *dt = [scannedResult dataUsingEncoding:NSUTF8StringEncoding];//dt с байтами
            scannedResult = [[NSString alloc] initWithData:dt encoding:NSUTF8StringEncoding];

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question