打印格式列表在Go lang [英] List of printing format in Go lang
本文介绍了打印格式列表在Go lang的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
例如:
%v用于打印值。
%T可以打印该类型的值。
还有什么?
解决方案
fmt软件包文档 :
常规:
%v默认格式的值。
打印结构时,加号标志(%+ v)添加字段名
%#va值的语法表示
%T a值的类型的Go语法表示
%%字面上百分号;消费没有价值
布尔值:
%t单词true或false
整数:
%b基数2
%c表示相应的字符Unicode代码点
%d base 10
%o base 8
%qa单引号字符文字安全地通过Go语法转义。
%x base 16,小写字母为a-f
%X base 16,大写字母为A-F
%U Unicode格式:U + 1234;与U +%04X相同
浮点和复杂的成分:
%b带指数的十进制小数科学记数法$ 2
$ p
的方式strconv.FormatFloat与' b'格式,
例如-123456p-78
%e科学记数法,例如-1234.456e + 78
%E科学记数法,例如-1234.456E + 78
%f小数点,但没有指数,例如123.456
%g,%e或%f产生更紧凑的输出
%G,无论哪个%E或%f产生更紧凑的输出
字符串和字节片段:
%s字符串或片断的未解释字节
%qa双引号字符串用Go语法安全地转义
%x base 16,小写字母,每个字节两个字符
%X base 16,大写,每字节两个字符
指针: p>
%p基数16表示法,带前导0x
其他标志:
+总是打印一个标志数值;
保证%q(%+ q)的仅ASCII输出
- 在右侧而不是在左侧的空格(左对齐字段)
#替换格式:添加前导0八进制(%#o),十六进制0x(%#x);
0X for hex(%#X);为%p(%#p)抑制0x;
打印原始(反引号)的字符串,如果可能的话为%q(%#q);
写入U + 0078'x'如果字符是可打印的%U(%#U)。
''(空格)留下一个空格,用于省略号码(%d);
在打印字符串或十六进制数据的字节之间放置空格(%x,%X)
0前导零而不是空格填充
Just want to know the list of printing format using the fmt package's functions.
For example, like:
%v is use for print the value. %T can print the type of value.
What else?
解决方案The list of format "verbs" is available in the documentation of the fmt package :
General:
%v the value in a default format. when printing structs, the plus flag (%+v) adds field names %#v a Go-syntax representation of the value %T a Go-syntax representation of the type of the value %% a literal percent sign; consumes no value
Boolean:
%t the word true or false
Integer:
%b base 2 %c the character represented by the corresponding Unicode code point %d base 10 %o base 8 %q a single-quoted character literal safely escaped with Go syntax. %x base 16, with lower-case letters for a-f %X base 16, with upper-case letters for A-F %U Unicode format: U+1234; same as "U+%04X"
Floating-point and complex constituents:
%b decimalless scientific notation with exponent a power of two, in the manner of strconv.FormatFloat with the 'b' format, e.g. -123456p-78 %e scientific notation, e.g. -1234.456e+78 %E scientific notation, e.g. -1234.456E+78 %f decimal point but no exponent, e.g. 123.456 %g whichever of %e or %f produces more compact output %G whichever of %E or %f produces more compact output
String and slice of bytes:
%s the uninterpreted bytes of the string or slice %q a double-quoted string safely escaped with Go syntax %x base 16, lower-case, two characters per byte %X base 16, upper-case, two characters per byte
Pointer:
%p base 16 notation, with leading 0x
Other flags:
+ always print a sign for numeric values; guarantee ASCII-only output for %q (%+q) - pad with spaces on the right rather than the left (left-justify the field) # alternate format: add leading 0 for octal (%#o), 0x for hex (%#x); 0X for hex (%#X); suppress 0x for %p (%#p); print a raw (backquoted) string if possible for %q (%#q); write e.g. U+0078 'x' if the character is printable for %U (%#U). ' ' (space) leave a space for elided sign in numbers (% d); put spaces between bytes printing strings or slices in hex (% x, % X) 0 pad with leading zeros rather than spaces
这篇关于打印格式列表在Go lang的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文