utf8.substr
Available inall 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
BETADo you see an error in this page? Do have an interesting use case, example or edge case people should know about? Share your knowledge and help people who are reading this page! (Comments are moderated; for support, please contact support@fastly.com)