iphone sdk – Remove all characters except for numbers 0-9 from a string [duplicate]

Simpler using iOS APIs only:

NSString * number = @"(555) 555-555 Office";
NSString * strippedNumber = [number stringByReplacingOccurrencesOfString:@"[^0-9]" withString:@"" options:NSRegularExpressionSearch range:NSMakeRange(0, [number length])];

Leave a Comment