Table. Keys
Returns all keys in the specified table.
Format:
Keys = table. Keys (Table object)
Usage example:
Local T = {A = 1, B = 2, c = 3}
Local keys = table. Keys (t)
-- Keys = {"A", "B", "C "}
~~
Table. Values
Returns all values in the specified table.
Format:
Values = table. Values (Table object)
Usage example:
Local T = {A = "1", B = "2", c = "3 "}
Local Values = table. Values (t)
-- Values = {1, 2, 3}
~~
Table. Merge
Merge two tables.
Format:
Table. Merge (target table object, source table object)
Copy all the keys and their values in the source table to the target table object. If a key with the same name exists, the value is overwritten.
Usage example:
Local DEST = {A = 1, B = 2}
Local src = {c = 3, D = 4}
Table. Merge (DEST, Src)
-- Dest = {A = 1, B = 2, c = 3, D = 4}
~~
String.html specialchars
Convert special characters to HTML encoding.
Format:
Result = string.html specialchars (string)
The following characters are converted:
'&' (Ampersand) to '& amp ;'
'(Double quote) to' & quot ;'
"'" (Single quote) to' & #039 ;'
'<' (Less than) to '& lt ;'
'>' (Greater than) to '& gt ;'
~~
String. nl2br
Converts a line break in a string to a line break Mark in HTML.
Format:
Result = string. nl2br (string)
Usage example:
Local text = "Hello \ nworld ."
Local result = string. nl2br (text)
-- Result = "Hello <br/> world ."
String. nl2br () and string.html specialchars () can be used in combination to convert strings to ensure that the conversion results meet HTML requirements and there are no security issues.
Local text = "---> Hello \ nworld <---"
Local result = string.nl2br(string.html specialchars (text ))
-- Result = "--- & gt; Hello <br/> & lt ;---"
~~
String. text2html
Format the string to make sure that all special characters are converted to HTML tags.
Format:
Result = string. text2html (string)
String. text2html () not only converts special characters and line breaks, but also replaces the tab "\ t" with a space, and then replaces the space with "& nbsp ;".
~~
String. Split
Split the string.
Format:
Result = string. Split (string to be split, separator)
Usage example:
Local result = string. Split ("1, 2, 3 ",",")
-- Result = {"1", "2", "3 "}
~~
String. ltrim
Removes white spaces at the front of a string.
Format:
Result = string. ltrim (string)
Blank characters include space, tab "\ t", Line Break "\ n", and "\ r ".
Usage example:
Local result = string. ltrim ("\ n \ thello ")
-- Result = "hello"
~~
String. rtrim
Removes white spaces at the end of a string.
Format:
Result = string. rtrim (string)
~~
String. Trim
Removes spaces at both ends of a string.
Format:
Result = string. Trim (string)
~~
String. ucfirst
Returns an uppercase string.
Format:
Result = string. ucfirst (string)
~~
String. urlencode
Generate a string that complies with the URL specification.
Format:
Result = string. urlencode (string)
To pass data through a URL, all non-letters and numbers in the string are replaced with "% encoding", and spaces are replaced with "+ ".
~~
String. utf8len
Calculates the number of characters contained in a UTF-8 string.
Format:
Count = string. utf8len (string)
When an utf8 string contains Chinese characters, String. Len () returns the length of the string in bytes. String. utf8len () always returns the number of characters in the string.
~~
String. formatnumberthousands
Format the number into a kilobytes.
Format:
Result = string. formatnumberthousands (numerical value)
Usage example:
Local result = string. formatnumberthousands (12345)
-- Result = "12,345"
Use of string strings in Lua (string. Len, String. Char)