Saturday, 18 February 2017

ios - iPhone phone number format NSFormatter




I'm copying phone number from iPhone address book to a text field. In text field it is showing as 1 (234) 567-8901. I want format it to 12345678901.
Any help?


Answer



You can use stringByReplacingOccurrencesOfString: withString: to remove characters you don't want such as @"(" with @""



EDIT: Better solution.



NSCharacterSet *charSet =[NSCharacterSet characterSetWithCharactersInString:@"()- "];
cleanedPhoneNumber = [phoneNumberString stringByTrimmingCharactersInSet:charSet];


No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...