• 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: internally trimming characters
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: internally trimming characters


  • Subject: Re: internally trimming characters
  • From: Christopher Drum <email@hidden>
  • Date: Wed, 30 Mar 2005 21:41:12 -0800

Is there an easy way to remove characters belong to a set (like numbers) from anywhere in a string? stringByTrimmingCharacters only works on the ends of the string.


This is the easiest way I know of, personally...

NSCharacterSet *digits = [NSCharacterSet decimalDigitCharacterSet];
NSMutableString *originalWord = [NSMutableString stringWithString:@"F1o2o3b4a5r"];
NSRange r = [originalWord rangeOfCharacterFromSet:digits];
while (r.location != NSNotFound) {
[originalWord deleteCharactersInRange:r];
r = [originalWord rangeOfCharacterFromSet:digits];
}

------------------------------------------------------------------
Christopher Drum
http://homepage.mac.com/christopherdrum

Check out FileWrangler, my five-star rated (MacUpdate, VersionTracker) batch file renamer and Bones, my five-star rated (MacUpdate, VersionTracker) virtual dice roller. They're both written in Cocoa with Objective-C.
 _______________________________________________
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

  • Prev by Date: Re: adding NSView from other application
  • Next by Date: Re: NSDate dateWithNaturalLanguageString goes BOOM! after being called 100, 000+ times
  • Previous by thread: internally trimming characters
  • Next by thread: Insetting a complex NSBezierPath shape?
  • Index(es):
    • Date
    • Thread