Skip to main content

len

Function len 

Source
pub fn len(s: string, i: option<number>, j: option<number>) -> option<number>
Expand description

Returns the number of UTF-8 characters in string s that start between byte positions i and j (default 1 and −1). If it finds any invalid byte sequence, returns nil plus the position of the first invalid byte.

§Examples

print(utf8.len("héllo"))    --> 5
print(#"héllo")             --> 6   (é takes two bytes)
print(utf8.len("\xFF"))     --> nil   1   (invalid byte at position 1)