• 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: Newbie: Encoding NSData to a string
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Newbie: Encoding NSData to a string


  • Subject: Re: Newbie: Encoding NSData to a string
  • From: James Bucanek <email@hidden>
  • Date: Sun, 25 Mar 2007 22:39:38 -0700

Joao Lourenco wrote on Monday, March 26, 2007:
>I'm starting to learn Cocoa and would like to do the following
>
>Read an image from a file
>Encode the image as an "ascii" string
>Send the image as an ASCII string in the body of a post message
>
>This is the code I have so far:
<clip>
>NSString* stringEncodedPicture = [[NSString alloc] initWithData:
>dataEncodedPicture  encoding: NSUTF8StringEncoding];

This will not work. +[NSString initWithData:...] interpret a sequences of bytes as an encoded string. An image is not an encoded string.

What you need to do is _encode_ the sequence of bytes into a string. I'd suggest base64. This is what XML and property lists use to encode arbitrary binary data. There should be a base64 encoding routine handy, I just can't remember where to fine one at the moment. Maybe someone else knows.

--
James Bucanek
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Newbie: Encoding NSData to a string
      • From: Christopher Hickman <email@hidden>
References: 
 >Newbie: Encoding NSData to a string (From: Joao Lourenco <email@hidden>)

  • Prev by Date: Re: Newbie: Encoding NSData to a string
  • Next by Date: Fwd: Compositing shrunk cells
  • Previous by thread: Re: Newbie: Encoding NSData to a string
  • Next by thread: Re: Newbie: Encoding NSData to a string
  • Index(es):
    • Date
    • Thread