Switching from NSString to NSData for byte input from file. (Was: Reading individual bytes from a string)
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