Your cart is currently empty!
Golang: String Format
%% | prints a single % |
%b | binary integer |
%c | a character represented by the corresponding Unicode code point |
%d | decimal integer |
%e | scientific notation (mantissa/exponent), lowercase |
%E | scientific notation (mantissa/exponent), uppercase |
%f | decimal floating point, lowercase |
%F | decimal floating point, uppercase |
%g | the shortest representation of %e or %f |
%G | the shortest representation of %E or %F |
%o | octal integer |
%O | octal integer with 0o prefix |
%p | pointer address |
%q | a quoted character |
%s | a string |
%t | boolean, the word true or false |
%T | a Go-syntax representation of the type of the value |
%U | Unicode escape sequence |
%v | value, default format |
%+v | value, Display field names |
%#v | value, Go-syntax representation of the value |
%x | hexadecimal integer lowercase |
%X | hexadecimal 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:
Leave a Reply