lua之字符串格式化

[plain] view plaincopy
  1. a = 'aadsdf\"'  
  2. 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的字符

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章