String length: Difference between revisions

Character Length added
(Character Length added)
Line 349:
=={{header|Component Pascal}}==
Component Pascal encodes strings in UTF-16, which represents each character with 16-bit value.
 
===Character Length===
<lang oberon2>
MODULE TestLen;
 
IMPORT Out;
 
PROCEDURE DoCharLength*;
VAR s: ARRAY 16 OF CHAR; len: INTEGER;
BEGIN
s := "møøse";
len := LEN(s$);
Out.String("s: "); Out.String(s); Out.Ln;
Out.String("Length of characters: "); Out.Int(len, 0); Out.Ln
END DoCharLength;
 
END TestLen.
</lang>
 
A symbol ''$'' in ''LEN(s$)'' in Component Pascal allows to copy sequence of characters up to null-terminated character. So, ''LEN(s$)'' returns a real length of characters instead of allocated by variable.
 
Running command ''TestLen.DoCharLength'' gives following output:
<pre>
s: møøse
Length of characters: 5
</pre>
 
===Byte Length===
Anonymous user