• 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
Switching from NSString to NSData for byte input from file. (Was: Reading individual bytes from a string)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Switching from NSString to NSData for byte input from file. (Was: Reading individual bytes from a string)


  • Subject: Switching from NSString to NSData for byte input from file. (Was: Reading individual bytes from a string)
  • From: Phil Faber <email@hidden>
  • Date: Mon, 17 Apr 2006 21:56:43 +0100

On 17 Apr 2006, at 18:55, Ondra Cada wrote:

- are you sure you want to check *characters*, not *bytes*? In the latter case, NSData would be better than NSString;

I've look at my original code (shown here:)

NSOpenPanel *panel = [NSOpenPanel openPanel];
NSString *inputFile = [panel filename];
NSString *fileContents = [NSString stringWithContentsOfFile:inputFile];
[statusText setStringValue:[fileContents characterAtIndex:8]];


...and realised that I probably DO need to switch to using NSData instead of NSString as I specifically want to be able to read in BYTES (ASCII 0 through ASCII 255) rather than characters. So have tried instead:

	NSOpenPanel *panel = [NSOpenPanel openPanel];
	NSString *inputFile = [panel filename];
	NSData *fileContents = [NSData dataWithContentsOfFile:inputFile];

	oneByte = [fileContents subdataWithRange:NSMakeRange(8,1)];
	NSLog(@"%i",oneByte);

...but NSLog reports the byte read as "3744544" - and NOT a number from 0 through 255! This sounds like a memory address. (I switched to using NSLog because statusText didn't like having oneByte assigned to it!)

What am I doing wrong? I'd tear my hair out if it wasn't for the fact that I didn't have any left to tear out!

Thanks!

Phil


___________________________________________________________ Switch an email account to Yahoo! Mail, you could win FIFA World Cup tickets. http://uk.mail.yahoo.com
_______________________________________________
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: Switching from NSString to NSData for byte input from file. (Was: Reading individual bytes from a string)
      • From: Alan Hart <email@hidden>
References: 
 >Setting a custom NSImageCell (From: Jim Turner <email@hidden>)
 >Re: Setting a custom NSImageCell (From: Mike Abdullah <email@hidden>)
 >Reading individual bytes from a string (From: Phil Faber <email@hidden>)
 >Re: Reading individual bytes from a string (From: Ondra Cada <email@hidden>)

  • Prev by Date: NSNoSelectionPlaceholderBindingOption
  • Next by Date: Re: Switching from NSString to NSData for byte input from file. (Was: Reading individual bytes from a string)
  • Previous by thread: Re: Reading individual bytes from a string
  • Next by thread: Re: Switching from NSString to NSData for byte input from file. (Was: Reading individual bytes from a string)
  • Index(es):
    • Date
    • Thread