Jump to content

String length: Difference between revisions

Merged the two programs in a single one. Added output.
No edit summary
(Merged the two programs in a single one. Added output.)
Line 2,076:
 
=={{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>varimport s: string = "Hellostrformat, world! ☺"unicode
echo '"',s, '"'," has byte length: ", len(s)
 
#var ->s: string = "Hello, world! ☺" has unicode char length: 17</lang>
 
echo '&"',“{s, '"',"}” has byte length: {s.len}.", len(s)
===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}}
# -> "Hello, world! ☺" has unicode char length: 15</lang>
<pre>“Hello, world! ☺” has byte length 17.
# -> "Hello“Hello, world! ☺"☺” has unicodeUnicode char length: 15.</langlen>
 
=={{header|Oberon-2}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.