Skip to content

slice

Slices a string with offsets and strides.

slice(x:string, [begin=int, end=int, stride=int])

The slice function takes a string as input and selects parts from it.

The string to slice.

The offset to start slice from.

If negative, offset is calculated from the end of string.

Defaults to 0.

The offset to end the slice at.

If negative, offset is calculated from the end of string.

If unspecified, ends at the input’s end.

The difference between the current character to take and the next character to take.

If negative, characters are chosen in reverse.

Defaults to 1.

from {x: "123456789"}
x = x.slice(end=3)
{x: "123"}
from {x: "1234567890"}
x = x.slice(stride=2, end=6)
{x: "135"}

Select a substring from the 2nd character up to the 8th character

Section titled “Select a substring from the 2nd character up to the 8th character”
from {x: "1234567890"}
x = x.slice(begin=1, end=8)
{x: "2345678"}