Bill Hernandez wrote:

I've worked with lots of number formatters over the years, and that is what they do, format numbers into strings, any kind of string...

I looked at the header file for NSNumberFormatter, and there seem to be 9,000,000+ methods, it is amazing. Buried in there, there has to be a simple way to format a string, that I am overlooking ?

If you look the simple formatter I wrote up last night, it will format a string digits any way imaginable.

Your code formats strings (more specifically, characters in strings). It does not format numbers, as such.

By "number" I mean a binary numeric value (floating-point or integer), or possibly NSNumber or NSDecimalNumber.

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.

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.

  -- GG

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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 arch...@mail-archive.com

Reply via email to