• 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: extracting numbers from NSString
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: extracting numbers from NSString


  • Subject: Re: extracting numbers from NSString
  • From: Hamish Allan <email@hidden>
  • Date: Wed, 1 Feb 2006 11:42:44 +0000


On Tue, 31 Jan 2006 16:02:08 -0500, Koen van der Drift wrote:

I am trying to extract some numbers from an NSString and store them
in an array (as an NSString, not as an NSNumber).

The original string has a format such as:

test (1.2.3 4.5.6)

The array should look like {123, 456}, so only numbers are left,
without the periods.

NSMutableString *workingString = [[originalString stringByTrimmingCharactersInSet:
[[NSCharacterSet decimalDigitCharacterSet] invertedSet]] mutableCopy];
[workingString replaceOccurencesOfString:@"." withString:@""
options:0 range:NSMakeRange(0, [workingString length])];
NSArray *result = [workingString componentsSeparatedByString:@" "];
[workingString release];


Best wishes,
Hamish

_______________________________________________
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:
    • Re: extracting numbers from NSString
      • From: Koen van der Drift <email@hidden>
  • Prev by Date: How to do multilanguage support
  • Next by Date: Re: extracting numbers from NSString
  • Previous by thread: Re: How to do multilanguage support
  • Next by thread: Re: extracting numbers from NSString
  • Index(es):
    • Date
    • Thread