Phone numbers can contain asterisks and number signs ( * and # ), and can start with + . Recommendation ITU-T Recommendation E-123 recommends using the + symbol to indicate that the number is an international number, and also serve as a reminder that the international dialing sequence for a particular country should be used instead.
You cannot type spaces, hyphens, or parentheses, so they do not matter in the phone number. To cut out all useless characters, you must delete all characters not in the decimal character set except * and # , as well as any + not found at the beginning of the phone number.
As far as I know, there is no standardized or recommended way to represent manual extensions (some use x , some use ext , some use E ). Although, I have not come across a manual extension for a long time.
NSUInteger inLength, outLength, i; NSString *formatted = @"(123) 555-5555"; inLength = [formatted length]; unichar result[inLength]; for (i = 0, outLength = 0; i < inLength; i++) { unichar thisChar = [formatted characterAtIndex:i]; if (iswdigit(thisChar) || thisChar == '*' || thisChar == '#') result[outLength++] = thisChar; // diallable number or symbol else if (i == 0 && thisChar == '+') result[outLength++] = thisChar; // international prefix } NSString *stripped = [NSString stringWithCharacters:result length:outLength];
dreamlax
source share