2

I hava a NSData object which represents a NSString object. I use -[NSString initWithData:encoding:] to get the string. Now the problem is how do I know the correct encoding type?

Thanks.

Edited: I test and find: the supposing the NSData is encoding with A, and I try to use encoding B to create the NSString. Sometimes the string will be nil, but string can be not nil which is a messy code. So I can't get the correct string by testing the each encoding type.

scorpiozj
  • 2,687
  • 5
  • 34
  • 60

1 Answers1

0

If the data came from a file, you can try +[NSString stringWithContentsOfFile:usedEncoding:error:]. But the method seems to try only a few encodings. The ICU library supports more encodings.

cahn
  • 1,350
  • 1
  • 12
  • 24