Lua之字符串格式化例子和常用格式化参数介绍

a = 'aadsdf"'  
print(string.format("%q",a)) 

%d
十进制整数
%o
八进制整数
%x
十六进制整数,大写的话为 %X
%f
浮点型 格式 [-]nnnn.nnnn
%e
科学表示法 格式 [-]n.nnnn e [+|-]nnn, 大写的话为 %E
%g
floating-point as %e if exp. < -4 or >= precision, else as %f ; uppercase if %G .
%c
character having the (system-dependent) code passed as integer
%s
没有的字符串
%q
双引号间的string, with all special characters escaped
%%
' % ' 字符
%a 字母
%c控制字符
%d多个数字
%l 小写字母
%p标点符号
%s空白字符
%x十六进制
%z内部表示为0的字符