String
string.len
Shared
Retrieves the length of a string in bytes
Syntax
local length = string.len(input)Parameters
| Type | Name | Description |
|---|---|---|
string | input | String to be measured |
Returns
| Type | Name | Description |
|---|---|---|
int | length | Length of the string in bytes |
Examples
local len = string.len("hello")
engine.print("info", len) --5local len = string.len("")
engine.print("info", len) --0local len = string.len("hello world")
engine.print("info", len) --11local len = string.len("hello\nworld")
engine.print("info", len) --11local len = string.len("hello\0world")
engine.print("info", len) --11local len = string.len("12345")
engine.print("info", len) --5local len = #"hello"
engine.print("info", len) --5local str = "Lua programming"
engine.print("info", string.len(str)) --15
engine.print("info", #str) --15
engine.print("info", string.len(len)) --15local str = "hello™"
engine.print("info", string.len(str)) --8if string.len("test") > 0 then
engine.print("info", "String is not empty")
endlocal str = " hello "
local trimmed = string.gsub(str, "^%s+", "")
trimmed = string.gsub(trimmed, "%s+$", "")
engine.print("info", string.len(str)) --9
engine.print("info", string.len(trimmed)) --5