Re: Reading individual bytes from a string
Re: Reading individual bytes from a string
- Subject: Re: Reading individual bytes from a string
- From: Ondra Cada <email@hidden>
- Date: Mon, 17 Apr 2006 19:55:29 +0200
Phil,
On 17.4.2006, at 19:02, Phil Faber wrote:
[statusText setStringValue:[fileContents characterAtIndex:8]];
Character is not a string. Character is a plain integer scalar value,
whilst a string is an object.
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;
- if you truly want characters, you should use the newer service
which allows you to set the string encoding.
stringWithContentsOfFile: is actually deprecated (since it has to use
some feebly-defined default encoding).
---
Ondra Čada
OCSoftware: email@hidden http://www.ocs.cz
private email@hidden http://www.ocs.cz/oc
_______________________________________________
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