types.String.len
Method on every
stringReturns the length of str in bytes.
Return value
The number of bytes in str. A Quirrel string is a byte buffer, not a sequence of code points: a 2-byte UTF-8 character counts as 2, not 1.
Notes
Takes no arguments; the VM reports the true arity here (len(): any), so there is nothing for a page to override.
Example
println("\"hello\".len() =", "hello".len())
// a Quirrel string is a byte buffer: this 2-byte UTF-8 character counts as 2.
let mb = "\xD0\x9F"
println("mb.len() =", mb.len())
try { "hello".len(1) } catch (e) println("\"hello\".len(1) throws:", e)Output:
"hello".len() = 5
mb.len() = 2
"hello".len(1) throws: wrong number of parameters passed to native closure 'len' (2 passed, 1 required)See also
slice | Returns the bytes of str from start up to, but not including, end. |
hasindex | Returns whether index is a valid byte position in str. |
| string | class index |