Reference › Function reference › Functions

Functions.text.trim

public

Call as

Functions.text.trim(s)

Record it as a dependency named Functions.text.trim (accepting the completion does this), then call it by that name.

Also accepted under the former namespace utils.

What it does

Remove leading and trailing Lua-pattern whitespace from a string.

Arguments

NameTypeWhat it does
sstringText to trim.

Returns

1stringTrimmed text.

Editions

Built In helpers are registered on every edition. What differs is the game API they read; where one is missing the helper falls back or returns nil with a reason.

It reads no game API directly.

Example

local name = Functions.text.trim(GetUnitName("target", false) or "")
return name ~= ""

Source

Functions/text.lua, line 54. Read only in game; Duplicate makes an editable copy.

Functions.text.trim(s)
    return (s:gsub("^%s*(.-)%s*$", "%1"))

Back to Function reference