lua脚本中string库用法整理(Usage of string Library in Lua script)
The 10:39 2007-5-1110:39 2007-5-11 bare Lua interpreter has limited functionality for manipulating strings. A program can create strings and connect strings, but can not intercept substring, check the size of the string, detect the content of the string. In Lua, the function of manipulating strings es from the string library.
Some of the functions in String is very simple: (s) returns a string length of S; (s, n) to repeat n times s string string; you use (a, 2^20) string can create a 1M bytes (for example, in order to test the required); (s) in the s will be converted to lowercase uppercase letters ( lowercase to uppercase). If you want to sort out an array without caring about the size, you can do that:
(a, function (a, b))
Return (a) < (b)
End)
Both and depend on local environment variables. So, if you're in the European Latin-1 environment, the expression:
("a?? o")
Return results: "A?? O"
Call the (s, I, J) function to intercept the string s from I characters to J characters. In Lua, the first character index of a string starts from 1. You can also use negative indexes, and negative indexes count forward from the end of the string: -1 points to the last character, -2 points to the last second, and so on. Therefore, (s, 1, J) returns the prefix length s of the string J, and (s, J, -1) returns the suffix starting from the J character. If the third parameter is not provided, the default is -1, so we write the last call to (s, J); (s, 2, -2) returns the substring that removes the first and last characters.
(s, n) - means: get the character from N in S.
S = "[in brackets]""
Print ( (s, 2, -2)) - > in brackets
Remember: the strings in Lua are immutable. The function and other strin
lua脚本中string库用法整理(Usage of string Library in Lua script) 来自淘豆网m.daumloan.com转载请标明出处.