Golang: String Format

%%prints a single %
%bbinary integer
%ca character represented by the corresponding Unicode code point
%ddecimal integer
%escientific notation (mantissa/exponent), lowercase
%Escientific notation (mantissa/exponent), uppercase
%fdecimal floating point, lowercase
%Fdecimal floating point, uppercase
%gthe shortest representation of %e or %f
%Gthe shortest representation of %E or %F
%ooctal integer
%Ooctal integer with 0o prefix
%ppointer address
%qa quoted character
%sa string
%tboolean, the word true or false
%Ta Go-syntax representation of the type of the value
%UUnicode escape sequence
%vvalue, default format
%+vvalue, Display field names
%#vvalue, Go-syntax representation of the value
%xhexadecimal integer lowercase
%Xhexadecimal integer uppercase

Argument index

fmt.Printf("%[1]s %[3]s %[2]s", "apple", "banana", "orange")
# => "apple" "orange" "banana"
fmt.Printf("%[1]s %[1]q", "apple")
# => apple, "apple"

Golang string formating cheatsheet: fmt.Printf formatting tutorial and cheat sheet · YourBasic Go

Golang string handling cheatsheet: Go string handling overview [cheat sheet] · YourBasic Go

References:


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *