• 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
Re: Reading individual bytes from a string
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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
  • Follow-Ups:
    • Switching from NSString to NSData for byte input from file. (Was: Reading individual bytes from a string)
      • From: Phil Faber <email@hidden>
    • Re: Reading individual bytes from a string
      • From: Phil Faber <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>)

  • Prev by Date: Re: Question on thread communication
  • Next by Date: Re: Resolving a alias w/o mounting file systems
  • Previous by thread: Re: Reading individual bytes from a string
  • Next by thread: Re: Reading individual bytes from a string
  • Index(es):
    • Date
    • Thread