• 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: NSStrings and data bytes
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSStrings and data bytes


  • Subject: Re: NSStrings and data bytes
  • From: Ricky Sharp <email@hidden>
  • Date: Tue, 27 Jun 2006 08:06:25 -0500

On Monday, June 26, 2006, at 10:59PM, Damien Sorresso <email@hidden> wrote:

>On 26 Jun, 2006, at 9:31 PM, D.K. Johnston wrote:
>> I want to read the bytes from a file as an NSString so I can use
>> scanners, etc. But then I need to get at the original bytes in
>> order to process them. (Sometimes I even have to get the right and
>> left nibbles of a byte.) I've been playing around with NSString
>> methods like cStringUsingEncoding:, but I can't seem to get the
>> bytes back. Any suggestions?
>
>Go the other way around. Read the bytes into an NSData object and
>then use initWithData:encoding: to get the string for your text,
>specifying the proper encoding, of course. From there, just do your
>work with NSScanner on that object. (I assume the order in which your
>data and string are created doesn't matter.)

This will not work, because I believe the OP said that the data is a mixture of both binary data and text.  The binary data will be attempted to be decoded which will most likely cause a failure.

Having said that, what I would do is to read in the entire data as binary.  Then, extract byte ranges that are text and feed those bytes into string routines that can then decode them.

--
Rick Sharp
Instant Interactive(tm)

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >NSStrings and data bytes (From: "D.K. Johnston" <email@hidden>)
 >Re: NSStrings and data bytes (From: Damien Sorresso <email@hidden>)

  • Prev by Date: Re: Eject Key Code
  • Next by Date: NSXMLParser Problem
  • Previous by thread: Re: NSStrings and data bytes
  • Next by thread: NSStrings and data bytes
  • Index(es):
    • Date
    • Thread