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

NSStrings and data bytes


  • Subject: NSStrings and data bytes
  • From: "D.K. Johnston" <email@hidden>
  • Date: Mon, 26 Jun 2006 21:51:16 -0700

(Sorry, I forgot the subject line again.)

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.)


You can also use NSString's initWithBytes:length:encoding: if you just want to read in the data using the standard C libraries.



My problem is that the file I'm reading contains both data bytes and text bytes. The former are distinguished from the latter only by having their high bits set. So the first thing I want to do is use an NSScanner to separate the data bytes from the text bytes; and to do this I read the file as an NSString. (Why don't NSData objects have scanners?) This gives me one array of strings composed of the data bytes, and another array of strings composed of the text bytes. The text byte strings are fine just the way they are. But to use the data byte strings, I need to get the original bytes back again.


In the previous version of the programme, I did read the file as an NSData object. But then I found it complicated (and time-consuming) to separate the data bytes (high bit set) from the text ones. I also have to look for sub-sequences of data bytes, and this is so much simpler (and faster) using the rangeOfString: method. Or have I been missing something simple here?

dkj

_______________________________________________
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


  • Follow-Ups:
    • Re: NSStrings and data bytes
      • From: Chris Suter <email@hidden>
  • Prev by Date: Re: how do I use a SEL from another class?
  • Next by Date: Re: NSStrings and data bytes
  • Previous by thread: Re: NSStrings and data bytes
  • Next by thread: Re: NSStrings and data bytes
  • Index(es):
    • Date
    • Thread