String length: Difference between revisions
Content added Content deleted
No edit summary |
(Merged the two programs in a single one. Added output.) |
||
Line 2,076: | Line 2,076: | ||
=={{header|Nim}}== |
=={{header|Nim}}== |
||
In Nim, <code>len</code> returns the byte length of strings, ignoring the UTF-8 encoding. When dealing with Unicode strings, the module <code>unicode</code> must be used. |
|||
===Byte Length=== |
|||
<lang Nim> |
<lang Nim>import strformat, unicode |
||
⚫ | |||
var s: string = "Hello, world! ☺" |
|||
⚫ | |||
===Character Length=== |
|||
echo &"“{s}” has Unicode char length {s.runeLen}."</lang> |
|||
<lang Nim>import unicode |
|||
var s: string = "Hello, world! ☺" |
|||
echo '"',s, '"'," has unicode char length: ", runeLen(s) |
|||
{{out}} |
|||
⚫ | |||
<pre>“Hello, world! ☺” has byte length 17. |
|||
⚫ | |||
=={{header|Oberon-2}}== |
=={{header|Oberon-2}}== |