• 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: 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
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: Re: Adding bindings to a custom view - "simple" implementation
  • Next by Date: Re: Accessing Resources
  • Previous by thread: Re: Reading individual bytes from a string
  • Next by thread: Switching from NSString to NSData for byte input from file. (Was: Reading individual bytes from a string)
  • Index(es):
    • Date
    • Thread