• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Data to String: what encoding?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Data to String: what encoding?


  • Subject: Re: Data to String: what encoding?
  • From: Douglas Davidson <email@hidden>
  • Date: Sun, 15 Sep 2002 12:38:56 -0700

On Sunday, September 15, 2002, at 12:24 PM, Randall Crenshaw wrote:

There doesn't seem to be a method like -(NSStringEncoding)
stringEncoding; on NSData. How does one deal with
arbitrary encodings? My method should be able to open any
file that can be saved on the disk. I really don't want to
worry about encodings, but if I have to then I need a way
to discover them dynamically.

It is impossible in principle to determine the encoding used for an arbitrary file. If the file contains sufficient amounts of natural-language text, then a human reader can usually determine the intended encoding, but it is easy to produce files for which many different encodings might have been used. Any method of the sort you propose would be no more than a reasonable guess.

Take a look at what TextEdit does in this case: it allows the user to choose what encoding to use. If no choice is made, it will attempt to detect UTF-16 (by looking for a BOM), but otherwise will use a default encoding.

Douglas Davidson
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • [newbie] /r invoking button instead of going to textfield?
      • From: Ando Sonenblick <email@hidden>
    • Re: Data to String: what encoding?
      • From: Ondra Cada <email@hidden>
References: 
 >Data to String: what encoding? (From: Randall Crenshaw <email@hidden>)

  • Prev by Date: Data to String: what encoding?
  • Next by Date: Re: Data to String: what encoding?
  • Previous by thread: Data to String: what encoding?
  • Next by thread: Re: Data to String: what encoding?
  • Index(es):
    • Date
    • Thread