STRING::PRINTF
1g 2023 laplante@plcb.ca GOWEB/STRING — Formatted Output Printingtitle: “STRING::PRINTF” version: “1.0.0” date: 2023 author: “laplante@plcb.ca” section: “1g”
string::printf Formatted Output Printing
string::printf(format[, args])
printf(format[, args])
The printf
function outputs formatted text, similar to Go’s fmt.Printf
.
It supports a wide range of format verbs for various data types:
%!v(MISSING)
— default format for the value%!v(MISSING)
adds field names%!v(MISSING)
— Go-syntax representation of the value%!T(MISSING)
— Go-syntax representation of the type%
— literal percent sign%!t(MISSING)
— true
or false
%!b(MISSING)
— binary%!c(MISSING)
— character represented by the Unicode code point%!d(MISSING)
— decimal%!o(MISSING)
— octal%!O(MISSING)
— octal with 0o
prefix%!q(MISSING)
— single-quoted character literal (Go syntax escaped)%!x(MISSING)
— hexadecimal (lowercase)%!X(MISSING)
— hexadecimal (uppercase)%!U(MISSING)
— Unicode format: U+1234
%!b(MISSING)
— binary exponent notation%!e(MISSING)
/ %!E(MISSING)
— scientific notation%!f(MISSING)
/ %!F(MISSING)
— decimal%!g(MISSING)
/ %!G(MISSING)
— adaptive formatting (scientific or decimal)%!x(MISSING)
/ %!X(MISSING)
— hexadecimal floating point%!s(MISSING)
— uninterpreted string bytes%!q(MISSING)
— double-quoted Go syntax escaped string%!x(MISSING)
/ %!X(MISSING)
— hexadecimal (lower/upper), 2 characters per byte%!p(MISSING)
— base-16 pointer (leading 0x
)Width & Precision
*
to pass width/precision as an int
argumentFlags
+
— always print sign-
— left-justify#
— alternate format (e.g., 0b
, raw string)0
— zero paddingres={{
a := [1, 2.2, "3"];
printf("%!T(MISSING) %!T(MISSING) %!T(MISSING)\n", a);
}}.
Returns:
res=int64 float64 string
res={{
a := [1, 2.2, "3", [1,2,3]];
printf("%!T(MISSING) %!T(MISSING) %!T(MISSING) %!T(MISSING)\n", a);
}}.
Returns:
res=int64 float64 string int64
%!!(MISSING)(EXTRA int64=2, int64=3)
laplante@plcb.ca