util.string.insert
Shared
Inserts a substring into a string at a given character position
Syntax
local result = util.string.insert(
input,
position = nil,
substring
)Parameters
| Type | Name | Description |
|---|---|---|
string | input | String to insert into |
int | position | Character position to insert at - negative counts from end - when omitted, substring is appended |
string | substring | String to insert |
Returns
| Type | Name | Description |
|---|---|---|
string | result | String with substring inserted |
Examples
local result = util.string.insert("hello", "!")
core.engine.print("info", result) -- 'hello!'local result = util.string.insert("hello", 1, "X")
core.engine.print("info", result) -- 'Xhello'local result = util.string.insert("hllo", 2, "e")
core.engine.print("info", result) -- 'hello'local result = util.string.insert("hello", -1, "p")
core.engine.print("info", result) -- 'hellpo'