Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Re: internally trimming characters
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: internally trimming characters



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



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.