• 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: [Newbie] Extracting a specific character number from a string
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Newbie] Extracting a specific character number from a string


  • Subject: Re: [Newbie] Extracting a specific character number from a string
  • From: Ricky Sharp <email@hidden>
  • Date: Wed, 6 Aug 2008 17:32:51 -0500


On Aug 6, 2008, at 5:23 PM, Phil Faber wrote:

I'm trying to learn more about string manipulation and want to be able to extract a single character from a string. I think I need to use subStringWithRange (exacting from and to the same character location) but I'm not sure and I'm also unsure how to code it.

Basically I'm after the equivalent of the old-fashioned BASIC command MID$ [ i.e. MID$("This is the sentence to check",4,1) to get character 4. ]

The following code works fine except for the..

NSLog(@"Character %i of %@ is %@",i,pass1,[pass1 substringWithRange: 1,2]);

The parameter to substringWithRange is a NSRange. So, you'll need to pass in something like:


NSMakeRange(1, 1)

Note also the second param to NSMakeRange is actually a length value and not an index.

...line simply because I don't know how to code that line. I think it's something to do with how to set the range that I'm getting wrong.

Can anyone please advise what than line is supposed to be to pull out the correct character?

But that is all overkill if you want to extract individual characters from a string. See NSString's characterAtIndex: API.


___________________________________________________________
Ricky A. Sharp         mailto:email@hidden
Instant Interactive(tm)   http://www.instantinteractive.com
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >[Newbie] Extracting a specific character number from a string (From: Phil Faber <email@hidden>)

  • Prev by Date: [Newbie] Extracting a specific character number from a string
  • Next by Date: Re: [Newbie] Extracting a specific character number from a string
  • Previous by thread: [Newbie] Extracting a specific character number from a string
  • Next by thread: Re: [Newbie] Extracting a specific character number from a string
  • Index(es):
    • Date
    • Thread