substr()

Extract a substring from a string.

Signature

substr(string, start [, length])

Parameters

Returns

Extracted substring

Examples

Extract from start position:

text = "hello world"
print(substr(text, 0, 5))       // "hello"
print(substr(text, 6))          // "world"

Negative indices from end:

text = "hello"
print(substr(text, -2))         // "lo"
print(substr(text, -3, 2))      // "ll"

Extract characters:

word = "duso"
print(substr(word, 1, 2))       // "us"
print(substr(word, 0, 1))       // "d"

See Also