Re: Reading individual bytes from a string
Re: Reading individual bytes from a string
- Subject: Re: Reading individual bytes from a string
- From: Phil Faber <email@hidden>
- Date: Mon, 17 Apr 2006 20:17:25 +0100
On 17.4.2006, at 19:02, Phil Faber wrote:
[statusText setStringValue:[fileContents characterAtIndex:8]];
The above could be done e.g. this way
[statusText setStringValue:[fileContents
substringWithRange:NSMakeRange(8,1)]];
or perhaps (different outcome, but I *guess* it might be closer to
what you actually want)
[statusText setIntValue:[fileContents characterAtIndex:8]];
(My next goal will be to get the programme to examine EVERY
character in the file, one after the other, and then write those
characters back to a new file)
Note also
- you should test whether there is at least 8 characters in the
string (see the recent thread "Empty NSStrings, nil NSStrings");
- depending what you exactly want to do with the characters, the
characterAtIndex: service would probably be better and more
efficient than substringWithRange:; just keep in mind it returns a
plain character, not a string object;
- are you sure you want to check *characters*, not *bytes*? In the
latter case, NSData would be better than NSString;
Actually, I really want to check BYTES as you suggest. I thought I
had to start with an NSString and convert it to an ASCII code. (Your
suggest codes of:
[statusText setIntValue:[fileContents characterAtIndex:8]];
..worked great for this as it returned the number 65 for an "A" which
is what I wanted!)
OK. So now I need to investigate NSData.
Onwards & upwards... [I've got a headache!]
Phil
___________________________________________________________
24 FIFA World Cup tickets to be won with Yahoo! Mail 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