0

I want to guess a received NSData's encoding. I searched in Stackoverflow and found one answer here which indicates "can't".

However, I noticed a NSString method stringWithContentsOfFile:usedEncoding:error:, and I wanted to know whether I can achieve this goal in sequence below:
1> Get an NSData object
2> Store this NSData object into a file with random file name in directory /tmp
3> Call NSString's stringWithContentsOfFile:usedEncoding:error: method to read from this temporary file.
4> Delete the temporary file.
5> Read the enc parameter to determine the encoding

I know I can experiment by myself, but I have no various data source with different encoding in my hand. Therefore I raised a question here. Could my opinion work? Could this solution find every possible encoding OS X could recognized?

Community
  • 1
  • 1
Andrew Chang
  • 1,289
  • 1
  • 18
  • 38
  • Don't guess about encodings ;) – Jason Coco Aug 29 '13 at 02:48
  • Why? I have an application to fetch target device's wireless network IDs and display them. But those IDs may in various encoding which may cause display errors... :( – Andrew Chang Aug 29 '13 at 03:01
  • What I meant is: SSIDs – Andrew Chang Aug 29 '13 at 03:12
  • Yeah, it's a really tough problem to solve :( your solution could work, but even if the string is not `nil` (meaning that the framework was able to "guess"), the guess could be totally wrong and end up showing your user total nonsense. You should try your solution and enter a lot of strange SSID in different encodings and see how they work. – Jason Coco Aug 29 '13 at 03:15
  • Thanks! I will try every encoding I could guess and create. I may make _display_ as first thing to do, even displaying wrong. At least this make the application work. – Andrew Chang Aug 29 '13 at 03:26

0 Answers0