views:

103

answers:

1

Hello,

can someone please give me a hint, how I can convert any that a user can enter into a TextField or select from within the Adreebook into a given format? The Webservice I user wants all Number in a specific format. For Example:

+49 (123) 456789456 must be 49123456789456

0049 (123) 456789456 must be 49123456789456

+49 123 456789456 must be 49123456789456

Is there a Cocoa function that can help me with this? Or do I have to parse the string and code a custom solution?

Thank you very much

twickl

A: 

Try

NSCharacterSet* illegal = [NSCharacterSet characterSetWithCharactersInString: @" ()+"];
NSString* str = @"+49 (123) 456789456";
NSString* modded = [[str componentsSeparatedByCharactersInSet: illegal] componentsJoinedByString: @""];
ttvd
You can also add something like...if ([@"00" isEqualToString:[str substringToIndex:2]]) { modded = [[str substringFromIndex:2] componentsSeparatedByCharactersInSet:illegal]}
Dimitar Dimitrov