Home Contents | # string.trim | String | Core4 Lua Commands

## SYNOPSIS

1. result = string.trim(s [, i [, j]])
2. result = string.trimr(s [, i [, j]])
3. result = string.triml(s [, i [, j]])

## DESCRIPTION

These functions remove whitespace from the substring s[i], s[i+1], ···, s[j]. The default value for i is 1; the default value for j is the number of characters in s.

The function string.trim() removes both leading and trailing whitespace, while the function string.trimr() removes trailing whitespace and string.triml() removes leading whitespace.

Whitespace are all characters for which ctype.isspace() returns true.

## RETURN VALUE

Returns a string.

## EXAMPLE

> > >
print(string.format("[%s]", string.trim(" 12345 "))) print(string.format("[%s]", string.trimr(" 12345 "))) print(string.format("[%s]", string.triml(" 12345 ")))
[12345] [ 12345] [12345 ]