Re: NSScanner troubles
Re: NSScanner troubles
- Subject: Re: NSScanner troubles
- From: WT <email@hidden>
- Date: Sat, 11 Dec 2010 01:38:23 -0200
Hi Greg and Ken,
thank you both for the very fast response. Is that behavior of NSScanner documented anywhere? I read the docs but don't remember coming across it. I'm a bit stunned. What's the point of having a scanner if it ignores certain key aspects of the locale?
NSNumberFormatter is the way to go then.
Thanks again.
WT
Begin forwarded message:
> From: Greg Parker <email@hidden>
> Date: December 11, 2010 1:25:57 AM GMT-02:00
> To: WT <email@hidden>
> Cc: cocoa-dev Dev <email@hidden>
> Subject: Re: NSScanner troubles
>
> On Dec 10, 2010, at 7:06 PM, WT wrote:
>> I wrote some code to parse doubles from strings in a locale (pt_BR) where the grouping and decimal separators are "." and "," respectively (the exact opposite of en_US). It should be a piece of cake, but I'm not getting the correct results. Can someone please tell me what obvious fact I'm missing? I've been staring at this code for a while now and can't figure out what's wrong.
>
> NSScanner -scanDouble: rejects the grouping separator in every locale. It assumes numbers are written without the grouping separator.
>
> NSScanner does recognize the localized decimal separator. en_US "12345.6" and pt_BR "12345,6" should do what you want.
> From: Ken Thomases <email@hidden>
> Date: December 11, 2010 1:27:24 AM GMT-02:00
> To: WT <email@hidden>
> Cc: cocoa-dev Dev <email@hidden>
> Subject: Re: NSScanner troubles
>
> On Dec 10, 2010, at 9:06 PM, WT wrote:
>
>> Note that the scanner returns the wrong result when the string to be parsed contains a '.' but I can't see why.
>
> NSScanner doesn't understand group separators, regardless of locale. You want to look into NSNumberFormatter.
>
> Cheers,
> Ken
>
_______________________________________________
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