• 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
Data to String: what encoding?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Data to String: what encoding?


  • Subject: Data to String: what encoding?
  • From: Randall Crenshaw <email@hidden>
  • Date: Sun, 15 Sep 2002 12:24:20 -0700 (PDT)

Hi,

I am wanting to convert an NSData to NSString. The data
came from a file. I have no idea what it's encoding is -
could be anything AFAIK.

NSData *d = [NSData dataWithContentsOfFile:filename];
// do something that requires an NSData object
// if it doesn't work, well, then it needs to be a String
NSString *s = [[NSString alloc] initWithData:d
encoding:XXXXXX];


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.

I do not want to re-read the file from disk using
stringWithContentsOfFile:. Can encoding: be nil in
initWithData:encoding:?

It's possible that I'm going about this backwards. Maybe I
should just read the string first and then convert it to
NSData which doesn't require knowledge of encodings...

Thanks!
Randy
Yahoo! Autos - Get free new car price quotes
http://autos.yahoo.com
_______________________________________________
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:
    • Re: Data to String: what encoding?
      • From: Douglas Davidson <email@hidden>
  • Prev by Date: Re: Obj-C question: protocol usage and inheritance
  • Next by Date: Re: Data to String: what encoding?
  • Previous by thread: Re: Obj-C question: protocol usage and inheritance
  • Next by thread: Re: Data to String: what encoding?
  • Index(es):
    • Date
    • Thread