在我們的代碼中有某些場景,當我們處理字符串時,我們可能希望某些字符串是小寫的,例如考慮使用身份驗證服務的 API 的一個非常基本的情況,並且該身份驗證服務的密碼應該小寫,在這種情況下,我們需要將用戶輸入的任何密碼轉換為小寫。
在 Lua 中將字符串轉換為小寫是由string.lower() 函數。
用法
string.lower(s)
在上麵的語法中,標識符 s 表示我們試圖將其轉換為小寫的字符串。
示例
讓我們考慮一個非常簡單的例子,我們將字符串文字轉換為小寫。
考慮下麵顯示的例子 -
s = string.lower("ABC")
print(s)
輸出
abc
一個重要的注意事項string.lower()函數是它不修改原始字符串,它隻是對其副本進行修改並返回該副本。讓我們借助一個例子來探索這個特殊案例。
示例
考慮下麵顯示的例子 -
s = "ABC"
s1 = string.lower("ABC")
print(s)
print(s1)
輸出
ABC abc
此外,如果一個字符串已經是小寫形式,那麽什麽都不會改變。
示例
考慮下麵顯示的例子 -
s = "a"
string.lower("a")
print(s)
輸出
a
相關用法
- Lua string.char()用法及代碼示例
- Lua string.gsub()用法及代碼示例
- Lua string.byte()用法及代碼示例
- 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.lower() function in Lua programming。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。