Strings in Lua are handled using the built-in string data type. There are no specific classes for narrow and wide strings like in the C++ API. Lua strings are considered to be in UTF-8 format and converted to and from wide strings when they are pass as function arguments or returned from an API function.
In Lua, strings can be created using string literals like so:
local s = "Hello!"
Common numeric data types can be converted to a string using the tostring function:
local s1 = tostring(2) -- integer to string conversion
local s2 = tostring(2.43434) -- float to string conversion
Narrow to wide string conversion is not relevant in Lua, as there is no separate wide string type.
To convert a string to an integer or floating point value, Lua provides the tonumber function:
local n = tonumber("465")
local f = tonumber("3.14")
The following functions are available, in addition to the Lua language string library.
Property | Type | Description |
---|---|---|
Find | Function | performs a search operation |
Left | Function | returns leftmost characters |
Len | Function | returns the length of the string |
Lower | Function | returns the string to lowercase |
Mid | Function | returns the length of the string |
Replace | Function | performs a search and replace operation |
Right | Function | returns rightmost characters |
Split | Function | segments the string |
StartsWith | Function | compares the beginning of two strings |
Trim | Function | removes whitespace characters from the ends of the string |
Upper | Function | converts the string to uppercase |
Xor | Function | performs an XOR operation |
Uuid | Function | creates a unique universal identifier |