Search⌘ K
AI Features

Format Specifiers: Formatted Element Output

Explore how to use format specifiers in D to control formatted output of elements within arrays and associative arrays. Understand how to customize delimiters, quotes for strings and characters, and display key-value pairs effectively.

Formatted element output

Format specifiers between %( and %) are applied to every element of a container (e.g. an array or a range):

D
import std.stdio;
void main() {
auto numbers = [ 1, 2, 3, 4 ];
writefln("%(%s%)", numbers);
}

The format string above consists of three parts:

  • %(: start of element format

  • %s: format for each element

  • %): end of element format

Each element is printed ...