utf8.substr

STRINGutf8.substrSTRINGsINTEGERoffsetINTEGERlength

Available in all subroutines.

Returns a substring of the UTF-8 string s, starting from the Unicode code point offset, of Unicode code point length. The substring is a copy of the original bytes.

For example, substr("%u{3b1}%u{3b2}%u{3b3}", 1, 1) is "β". See substr for the exact semantics of the offset and length.

If the input string is not valid UTF-8, an unset value is returned.

IMPORTANT: UTF-8 allows you to combine characters, which are separate code points. While utf8.substr correctly honors the Unicode code point boundaries, however, requesting a substring of several of them may not necessarily represent a meaningful grapheme cluster.

User contributed notes

We welcome comments that add use cases, ideas, tips, and caveats. All comments will be moderated before publication. To post support questions, visit our support center and we'll find you the help you need.