Although this has already been answered/accepted, I have a better solution without needing an external SDK. Create an additional NSString method in a category like this:
@interface NSString (Helpers)
- (NSString*)stringByRemovingCharactersInSet:(NSCharacterSet*)set;
@end
@implementation NSString (Helpers)
- (NSString*)stringByRemovingCharactersInSet:(NSCharacterSet*)set
{
NSArray* components = [self componentsSeparatedByCharactersInSet:set];
return [components componentsJoinedByString:@""];
}
@end
Now you can use stringByRemovingCharactersInSet instead of stringByTrimmingCharactersInSet. However I'd also recommend another slight change to your example code, to support the '+' character in international numbers, as follows:
NSString* number = @"(555) 555-555 Office";
NSCharacterSet* phoneChars = [NSCharacterSet characterSetWithCharactersInString:@"+0123456789"];
NSString* strippedNumber = [number stringByRemovingCharactersInSet:[phoneChars invertedSet]];
NSString* urlString = [NSString stringWithFormat:@"tel:%@", strippedNumber];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];