5

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.

8
  • 4
    Why you not use the Delphi SysUtils.Format function is very complete. docwiki.embarcadero.com/VCL/en/SysUtils.Format ? Commented May 12, 2011 at 4:55
  • Of course I'm using Format function. But it can't support changing argument order. It's not useful especially for translating message text into several languages. Commented May 12, 2011 at 8:00
  • 3
    It does support changing argument order: Format('%1:s - %0:d', [7, 'Text']) Commented May 12, 2011 at 8:55
  • Please be more precise about what aspects of the .Net function you're looking for in Delphi. In a comment you mention argument order. Do you also require the brace syntax? The ability to omit type information from the composite format? Arbitrary objects in the argument list? Commented May 12, 2011 at 14:08
  • 1
    Don't delete the question, looks valuable to me. Compile your own answer from RRUZ's comment and possibly mine and post it as an answer. I initially gave a similar answer to RRUZ's comment myself, but immediately deleted it when I saw RRUZ's comment was 9 minutes earlier. Commented May 13, 2011 at 6:24

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.