String length: Difference between revisions

Content deleted Content added
add task to aarch64 assembly raspberry pi
adding lambdatalk
Line 1,706: Line 1,706:


[[File:LV strlen.png]]
[[File:LV strlen.png]]

=={{header|Lambdatalk}}==
The lambdatalk {W.length string} function returns the number of bytes in a string. For Unicode characters made of two bytes things are a little bit more tricky. It's easy to add (inline) a new javascript primitive to the dictionary:

<lang scheme>
{script
LAMBDATALK.DICT["W.unicodeLength"] = function() {
function countCodePoints(str) {
var point,
index,
width = 0,
len = 0;
for (index = 0; index < str.length;) {
point = str.codePointAt(index);
width = 0;
while (point) {
width += 1;
point = point >> 8;
}
index += Math.round(width/2);
len += 1;
}
return len;
}
var args = arguments[0].trim();
return countCodePoints(args)
};
}

Testing:

{W.length Hello, World!} -> 13

{W.length José} -> 4
{W.unicodeLength José} -> 4

{W.length 𝔘𝔫𝔦𝔠𝔬𝔡𝔢} -> 14
{W.unicodeLength 𝔘𝔫𝔦𝔠𝔬𝔡𝔢} -> 7
</lang>



=={{header|Lasso}}==
=={{header|Lasso}}==