Dynamically Create A Printf String Format
Formatting a string with Printf
requires defining a format for that string.
The format is the first argument. At compile-time it is interpreted as a format6
type value.
So, what if you want a dynamically created format value? Simply concatenating some strings together won't do it because then the type will be string
and that's not going to compile.
The Scanf.format_from_string
function can help.
We can convert our string that has the appearance of a format into an actual format6
type. To do this, we have to tell format_from_string
what types each of the formats is going to have -- hence the second argument %s
.
PreviousDefining Variants With Constructor ArgumentsNextExhaustive Pattern Matching Of List Variants
Last updated