Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any .NET string.format compatible function for Delphi win32?

Is there any .NET string.format compatible function for Delphi Win32 ?

I want to use it's argument order syntax.

I found one at delphi3000.com, but it's pretty simple and without supporting number precition, etc.

Don't you know any better open-source implementation ?

Thanks.

like image 864
benok Avatar asked Nov 05 '22 22:11

benok


1 Answers

Use SysUtils.Format.

It also supports argument order syntax as string.format in .Net does.

You can change argument order like following example.

Format('%1:s - %0:d', [7, 'Text'])


As I was a C programmer, I thought SysUtils.Format was just like printf in C.

But SysUtils.Format is not just like "printf" and it's more powerful as RRUZ & Cosmin Prund taught me in the comments above. (I should have checked help ;-)

I wanted .Net's string.format mainly because I wanted to use it's famous argument order syntax.

Argument order syntax is useful especially for translating message text into languages (like English to Japanese), but I don't need .Net compatibility.

If you had to port .Net's code to Delphi win32, or you are very familiar with .Net's format syntax, these library would be useful if exists, but it isn't in my case.

like image 115
benok Avatar answered Nov 09 '22 11:11

benok