在很多情況下,您可能希望將十進製值轉換為字符表示。十進製或整數值的字符表示隻不過是字符值,可以使用 ASCII 表來解釋。
在 Lua 中,為了將十進製值轉換為其內部字符值,我們使用 string.char() 函數。
用法
string.char(I)
在上麵的語法中,標識符 I 表示我們要轉換為字符的十進製值。
示例
讓我們考慮一個非常簡單的示例,其中給定了不同的十進製值,並且您希望將它們轉換為字符值。
考慮下麵顯示的例子——
s = string.char(97)
print(s)
s = string.char(122)
print(s)
s = string.char(125)
print(s)
在上麵的示例中,作為參數傳遞給 string.char() 函數的值是與字符對應的十進製值。
輸出
a z }
這個string.char()函數也可以接受多個參數。
示例
考慮下麵顯示的例子——
i = 97
s = string.char(i,i+1,i+2,i+3)
print(s)
輸出
abcd
相關用法
- Lua string.gsub()用法及代碼示例
- Lua string.byte()用法及代碼示例
- Lua string.lower()用法及代碼示例
- Lua string.format()用法及代碼示例
- Lua string.upper()用法及代碼示例
- Lua table.pack()用法及代碼示例
- Lua io.popen()用法及代碼示例
- Lua table.unpack()用法及代碼示例
- Lua math.modf()用法及代碼示例
- Lodash _.isValidDate()用法及代碼示例
- Lodash _.isInteger()用法及代碼示例
- Lodash _.sampleSize()用法及代碼示例
- Lodash _.fromQuery()用法及代碼示例
- Lodash _.noConflict()用法及代碼示例
- Lodash _.Intersection()用法及代碼示例
- Lodash _.values()用法及代碼示例
- Less isstring()用法及代碼示例
- Lodash _.isLength()用法及代碼示例
- Lodash _.third()用法及代碼示例
- Lodash _.negate()用法及代碼示例
注:本文由純淨天空篩選整理自Mukul Latiyan大神的英文原創作品 string.char() function in Lua programming。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。