...

/

Format Specifiers: Positional Parameters and Format

Format Specifiers: Positional Parameters and Format

This lesson explains how to position parameters in format specifiers, followed by a discussion of the `format()` function of the `std.string` module.

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 ...

Access this course and 1400+ top-rated courses and projects.