/*
Strip out anything in the string that is not a digit
Original Source: <http://cocoa.karelia.com/Foundation_Categories/NSString/Strip_out_anything_.m>
(See copyright notice at <http://cocoa.karelia.com>)
*/

/*" Return a string consisting only of the digits in the string. For example, (916) 692-1560 is converted to 9166921560.
"*/

- (NSString *)digitsOnly
{
NSString *result = nil;
unsigned len = [self length];
unichar *buffer = malloc(len * sizeof(unichar));
NSCharacterSet *decimalDigits = [NSCharacterSet decimalDigitCharacterSet];
unsigned i;
unsigned j = 0;
for ( i = 0 ; i < len ; i++ )
{
unichar c = [self characterAtIndex:i];
if ([decimalDigits characterIsMember:c])
{
buffer[j++] = c;
}
}
result = [[[NSString alloc] initWithCharacters:buffer length:j] autorelease];
free(buffer);
return result;
}