String length: Difference between revisions
Content added Content deleted
(→go Byte Length: use same format for all entries) |
(→{{header|Julia}}: add Grapheme Length and use suggested examples) |
||
Line 1,800: | Line 1,800: | ||
=={{header|Julia}}== |
=={{header|Julia}}== |
||
Julia encodes strings as UTF-8, so the byte length (via <code>sizeof</code>) will be different from the string length (via <code>length</code>) only if the string contains non-ASCII characters. |
Julia encodes strings as UTF-8, so the byte length (via <code>sizeof</code>) will be different from the string length (via <code>length</code>) only if the string contains non-ASCII characters. |
||
===Byte Length=== |
===Byte Length=== |
||
<syntaxhighlight lang="julia"> |
<syntaxhighlight lang="julia"> |
||
sizeof("Hellö, wørld!") # gives 15</syntaxhighlight> |
|||
sizeof("møøse") # 7 |
|||
sizeof("𝔘𝔫𝔦𝔠𝔬𝔡𝔢") # 28 |
|||
sizeof("J̲o̲s̲é̲") # 13 |
|||
</syntaxhighlight> |
|||
===Character Length=== |
===Character Length=== |
||
<syntaxhighlight lang="julia"> |
<syntaxhighlight lang="julia"> |
||
length("Hellö, wørld!") # gives 13</syntaxhighlight> |
|||
length("møøse") # 5 |
|||
length("𝔘𝔫𝔦𝔠𝔬𝔡𝔢") # 7 |
|||
length("J̲o̲s̲é̲") # 8 |
|||
</syntaxhighlight> |
|||
===Grapheme Length=== |
|||
<syntaxhighlight lang="julia"> |
|||
import Unicode |
|||
length(Unicode.graphemes("møøse")) # 5 |
|||
length(Unicode.graphemes("𝔘𝔫𝔦𝔠𝔬𝔡𝔢")) # 7 |
|||
length(Unicode.graphemes("J̲o̲s̲é̲")) # 4 |
|||
</syntaxhighlight> |
|||
=={{header|K}}== |
=={{header|K}}== |