String length: Difference between revisions

→‎Lua: add unicode method
(→‎groovy Character Length: add recommended examples)
(→‎Lua: add unicode method)
Line 2,005:
 
In Lua, a character is always the size of one byte so there is no difference between byte length and character length.
 
===Byte Length===
 
Byte length in UTF-8:
 
<syntaxhighlight lang="lua">str = "Hello world"
length = #str</syntaxhighlight>
Line 2,015 ⟶ 2,019:
 
===Character Length===
 
Only valid for ASCII:
 
<syntaxhighlight lang="lua">str = "Hello world"
length = #str</syntaxhighlight>
Line 2,022 ⟶ 2,029:
<syntaxhighlight lang="lua">str = "Hello world"
length = string.len(str)</syntaxhighlight>
 
For Unicode string, use utf8 module:
 
<syntaxhighlight lang="lua">
utf8.len("møøse")
utf8.len("𝔘𝔫𝔦𝔠𝔬𝔡𝔢")
utf8.len("J̲o̲s̲é̲")
</syntaxhighlight>
 
{{out}}
 
<pre>
5
7
8
</pre>
 
=={{header|M2000 Interpreter}}==