util.string.remove

Shared

Removes a range of characters from a string


Syntax

local result = util.string.remove(
    input,
    start_at = -1,
    end_at = -1
)

Parameters

TypeNameDescription
stringinputString to remove characters from
intstart_atCharacter position to start removing from - negative counts from end
intend_atCharacter position to stop removing at (inclusive) - negative counts from end

Returns

TypeNameDescription
stringresultString with the given character range removed

Examples

Remove the last character by default
local result = util.string.remove("hello!")

core.engine.print("info", result) -- 'hello'
Remove a single character at a position
local result = util.string.remove("hello", 1, 1)

core.engine.print("info", result) -- 'ello'
Remove a range of characters
local result = util.string.remove("hello world", 6, 11)

core.engine.print("info", result) -- 'hello'
Remove characters counting from the end
local result = util.string.remove("hello", -3, -1)

core.engine.print("info", result) -- 'he'

On this page