String length: Difference between revisions

Add Ecstasy example
(Added various BASIC dialects)
(Add Ecstasy example)
 
(4 intermediate revisions by 4 users not shown)
Line 585:
<syntaxhighlight lang="qbasic"> INPUT a$
PRINT LEN(a$)</syntaxhighlight>
 
==={{header|ANSI BASIC}}===
The ANSI BASIC needs line numbers.
<syntaxhighlight lang="basic">
10 INPUT A$
20 PRINT LEN(A$)
</syntaxhighlight>
 
==={{header|Applesoft BASIC}}===
Line 1,289 ⟶ 1,296:
print len "😀"
</syntaxhighlight>
 
=={{header|Ecstasy}}==
<syntaxhighlight lang="ecstasy">
module StrLen {
@Inject Console console;
 
void run(String s = "José") {
console.print($|For the string {s.quoted()}:
| Character length: {s.size}
| UTF-8 byte length: {s.calcUtf8Length()}
);
}
}
</syntaxhighlight>
 
{{out}}
<pre>
For the string "José":
Character length: 4
UTF-8 byte length: 5
</pre>
 
=={{header|Elena}}==
Line 3,078 ⟶ 3,106:
 
Unfortunately, only character length can be retrieved in this language.
 
=={{header|RPL}}==
RPL strings are all made of 8-bit characters.
"RPL" SIZE
 
=={{header|Ruby}}==
Line 3,681 ⟶ 3,713:
di ustrlen(s)
47</syntaxhighlight>
 
=={{header|Stringle}}==
The only current implementation of Stringle uses 8-bit character sets, meaning character and byte length is always the same.
 
This prints the length of a string from input:
 
<syntaxhighlight lang="stringle">$ #$</syntaxhighlight>
 
=={{header|Swift}}==
Line 4,020 ⟶ 4,059:
=={{header|Wren}}==
===Byte Length===
<syntaxhighlight lang="ecmascriptwren">System.print("møøse".bytes.count)
System.print("𝔘𝔫𝔦𝔠𝔬𝔡𝔢".bytes.count)
System.print("J̲o̲s̲é̲".bytes.count)</syntaxhighlight>
Line 4,032 ⟶ 4,071:
 
===Character Length===
<syntaxhighlight lang="ecmascriptwren">System.print("møøse".count)
System.print("𝔘𝔫𝔦𝔠𝔬𝔡𝔢".count)
System.print("J̲o̲s̲é̲".count)</syntaxhighlight>
Line 4,045 ⟶ 4,084:
===Grapheme Length===
{{libheader|Wren-upc}}
<syntaxhighlight lang="ecmascriptwren">import "./upc" for Graphemes
 
System.print(Graphemes.clusterCount("møøse"))
162

edits