On Apr 13, 2010, at 8:09 PM, Murat Konar wrote:
> If you don't explicitly set a formatter behavior, you are probably getting
> the newest behavior "NSNumberFormatterBehavior10_4", and -setFormat: does
> require the older "NSNumberFormatterBehavior10_0" behavior. That's why your
> string is being returned unchanged. As far as the formatter is concerned, you
> have not set a format string.
>
> Note also that in your most recently posted code, you set the default
> behavior for the class *after* you allocate an instance. You should either
> set the default behavior before creating an instance, or set the behavior on
> the instance itself.
murat,
if I call:
phoneNumber = [BHUtility bhFormatNumberString:strippedNumber withFormat:@"(###)
###-####"];
run
[Switching to process 6314]
Running…
Current language: auto; currently objective-c
2010-04-13 22:48:23.398 Formatter[6314:a0f] [4625] theString = (1234567890) -
(gdb)
//
+---------+---------+---------+---------+---------+---------+---------+---------+
+ (NSString *)bhFormatNumberString:(NSString *)aNumberString
withFormat:(NSString *)aFormat
{
// THIS METHOD DOES NOT WORK
[NSNumberFormatter
setDefaultFormatterBehavior:NSNumberFormatterBehavior10_0];
NSNumberFormatter *numberFormatter = [[[NSNumberFormatter alloc] init]
autorelease];
// NSFormatter *numberFormatter = [[[NSNumberFormatter alloc] init]
autorelease];
[numberFormatter setFormat:aFormat]; // specify just positive values
format
NSInteger theInt = [aNumberString intValue];
NSNumber *theNum = [NSNumber numberWithInt:theInt];
NSString *theString = (NSString *)[numberFormatter stringFromNumber:theNum];
NSLog(@"[4625] theString = %@", theString);
return theString;
//
+---------+---------+---------+---------+---------+---------+---------+---------+
}
I came up with a better work-aroundthat I posted to the forum. Take a look at
it, it really works very well, and is not limited to phone numbers.
Thanks a million for trying to help me...
Bill Hernandez
Plano, Texas
_______________________________________________
Cocoa-dev mailing list ([email protected])
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]