Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2011-04

Default IntToStr operator for '+' symbol.

5 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Skybuck Flying

Hello,

I am not sure, maybe we discussed this before, maybe not.

I am getting quite sick of having to write IntToStr all the fricking time like so:

begin
    s := IntToStr(X) + ' ' + IntToStr(Y);
end;

So much typing for nothing ?!?

I could have written just:
begin
    s := X + ' ' + Y;
end;

Since there is a string inside this statement Delphi could be smart enough to understand that X and Y have to be converted to strings.

Since X en Y are for example integers, it's logical to call TryStrToInt for X and Y and if the conversion fails replace it with N.A. (for not available).

This way these integer to string conversions can be automatic.

The same could be done for floating points. Perhaps there is an issue with the precision of it... perhaps this could be some kind of default.

At least the automatic integer to string conversion is a good start.

Bye,
Skybuck.

Reply by email

Felipe Monteiro de Carvalho
to Skybuck Flying

The Pascal way to avoid using too much IntToStr is:

begin
  s := Format('%d %d', [X, Y]);
end;

Much shorter, no?

And you can configure in multiple ways how to format the numbers.

Felipe Monteiro de Carvalho

Reply by email

Skybuck Flying
to Felipe Monteiro de Carvalho: The Pascal way to avoid using too much IntToStr is: begin s := Format('%d %d', [X, Y]);…

----- Original Message -----

Earlier message 43 lines
From: "Felipe Monteiro de Carvalho" To: "FPC developers' list" Sent: Friday, 29 April, 2011 10:23 AM Subject: Re: [fpc-devel] Default IntToStr operator for '+' symbol. > The Pascal way to avoid using too much IntToStr is: > > begin > s := Format('%d %d', [X, Y]); > end; > > Much shorter, no? Barely, I absolutely hate that function, it's very unnatural and reminds me of C. It's pretty stupid though sometimes it can be handy to layout floats or currency or do special things, like add zeros in front. However I suspect there is a better way to layout these variables. I just had an idea how to better layout floats and such. The old way of laying them out in writeln can be used which I love and is great: Example: begin s := vSomeFloat:16:16 + ' ' + vSomeFloat:16:16; end; Perhaps someone can (later) come up with nice format specifiers. There is also a huge benefit of this new way above: The format specifier is immediatly associated with the variables no need to count place like in your case. (For two that is not much of a problem but it gets a bit nasty for 10 and beyond) Bye, Skybuck.

Reply by email

Daniël Mantione
to Skybuck Flying

Op Fri, 29 Apr 2011, schreef Skybuck Flying:

Show quoted text 8 lines
I just had an idea how to better layout floats and such. The old way of laying them out in writeln can be used which I love and is great: Example: begin s := vSomeFloat:16:16 + ' ' + vSomeFloat:16:16; end;

Good, then you really need to look into writestr, as Florian wrote, you will like it:

writestr(s,vSomeFloat:16:16,' ',vSomeFloat:16:16);

... works fine.

Daniël

Reply by email