Search⌘ K
AI Features

Format Specifiers: Positional Parameters and Format

Explore how to use format specifiers with positional parameters in D programming to create flexible output formats. Understand argument positioning for multilingual text, the format function for string output, and compile-time checked format strings to avoid errors.

Positional parameters

We have seen above that the arguments are associated one by one with the specifiers in the format string. It is also possible to use position numbers within format specifiers. This enables the specifiers to associate with specific arguments. Arguments are numbered in increasing fashion, starting with 1. The argument numbers are specified immediately after the % character, followed by a :

An advantage of positional parameters is being able to use the same argument in more than one place in the same format string:

writefln("%1$d %1$x %1$o %1$b", 42);

The format string above uses the argument numbered 1 within four ...