现在的位置: 首页 > 综合 > 正文

lua之字符串格式化

2013年10月16日 ⁄ 综合 ⁄ 共 360字 ⁄ 字号 评论关闭
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

没有\0的字符串

%q

双引号间的string, with all special characters escaped

%%

' % ' 字符

%a 字母

%c控制字符

%d多个数字

%l 小写字母

%p标点符号

%s空白字符

%x十六进制

%z内部表示为0的字符

抱歉!评论已关闭.