Re: internally trimming characters
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