Re: NSNumberFormatter not working for me ?
Re: NSNumberFormatter not working for me ?
- Subject: Re: NSNumberFormatter not working for me ?
- From: Chris Kane <email@hidden>
- Date: Thu, 15 Apr 2010 11:38:05 -0700
On Apr 14, 2010, at 6:38 PM, Bill Hernandez wrote:
> On Apr 14, 2010, at 5:25 PM, Greg Guerin wrote:
>
>> Your code formats strings (more specifically, characters in strings). It does not format numbers, as such.
>
> This is the work-around that I did because I could not make do with NSNumberFormatter.
>
>> By "number" I mean a binary numeric value (floating-point or integer), or possibly NSNumber or NSDecimalNumber.
>
> I've been programming the mac since 1987 pretty much full-time. so I promise you, I am not confused at all about what a number is, and isn't...
>
>> All your "number" parameters are actually of the NSString* type, not of a numeric type. The fact that the string contains digits is incidental. In a sense, converting a numeric value to NSString* is already a "formatting" operation, or at least a conversion operation.
>
> I think you missed the earlier messages. You are probably looking at the converter that I wrote as a work-around, which is basically a numeric string formatter.
>
>> Your code would work just as well if you passed it an alphabetic string, or one containing punctuation marks.
>>
>> strippedNumber = @"SueMeTomorrow"
>> format = @"Social Security : ###-##-###"
>> result = @"Social Security : Sue-Me-Tom"
>>
>> I'm not saying the digit-string isn't relevant to what you're doing, only that what you seem to think of as a number is, in fact, a string that happens to contain a series of digit characters. I think that was a point an earlier reply was trying to make: NSNumberFormatter is for numeric values (NSNumber, in particular), not string values that happen to contain digits.
I think people are confusing two issues, one being the abstract "phone numbers aren't numbers and NSNumberFormatter is only for quantities", and the other is the reason you don't get what you want out of NSNumberFormatter, in trying to explain. Let me try to explain the latter as directly as possible.
In this kind of example of the result you want:
> format = @"(###) ###-####"
> result = @"(123) 456-7890"
You're trying to format a number object with NSNumberFormatter and get the formatter to put junk in the middle of the number [digit sequence]. NSNumberFormatter does not support formats putting junk in the middle of the number, except for a limited set involving the thousands separator and the decimal point.
You're already doing the right thing for what you want to do by writing your own algorithm. You could mold that into the form of an NSFormatter subclass then, if that is useful to you, or just keep it off to the side as a helper function/method.
Chris Kane
Cocoa Frameworks, Apple
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden