Hi Balázs,
Thank you very much for your answer, it helped a lot. Sending the #printf message to the string seems a little counterintuitive.
How does the interpretor know that I mean to create an instance of the class FormatString, instead of String?
I looked at the Class definition and it just says that Format String is a subclass of Object. So how does the code
get executed?
If I can figure out how to put a method into the String class, then I can use the long worded code you have below and just
name it something easier.
Thanks so much,
Sincerely,
Joe.
> ------------------------------
>
> Message: 2
> Date: Sat, 6 Oct 2012 20:29:50 +0200
> From: Bal?zs K?si <
[hidden email]>
> Subject: Re: [squeak-dev] Printf class
> To: The general-purpose Squeak developers list
> <
[hidden email]>
> Message-ID:
> <CACeQCFaO4d8vvmLR4BAnYZjENeGaZd1q-aNK=
[hidden email]>
> Content-Type: text/plain; charset=ISO-8859-1
>
> Hi,
>
> I took a cursory look at the Printf package. You should send #printf:
> to the format string, with the data to be formatted as the arguments.
> There are some examples on the class side of FormatString. Your
> example could be written as:
> '%6.2e' printf: 12.343434 resulting in: ' 12.34'.
>
> String understands #format: which is the basic string interpolation
> method in Squeak, but it doesn't do any number formatting. The same
> formatting as above could be achieved with methods already in the
> trunk like this:
> (12.343434 printShowingMaxDecimalPlaces: 2) padded: #left to: 6 with:
> Character space
>
> Maybe there is a more concise way?
>
> HTH, Balázs