September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
2
Task/String-length/BASIC/string-length-3.basic
Normal file
2
Task/String-length/BASIC/string-length-3.basic
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
10 INPUT A$
|
||||
20 PRINT LEN(A$)
|
||||
|
|
@ -1,6 +1,11 @@
|
|||
#var s := "Hello, world!". // UTF-8 literal
|
||||
#var ws := "Привет мир!"w. // UTF-16 literal
|
||||
import extensions.
|
||||
|
||||
#var s_length := s length. // Number of UTF-8 characters
|
||||
#var ws_length := ws length. // Number of UTF-16 characters
|
||||
#var u_length := ws toArray length. //Number of UTF-32 characters
|
||||
program =
|
||||
[
|
||||
var s := "Hello, world!". // UTF-8 literal
|
||||
var ws := "Привет мир!"w. // UTF-16 literal
|
||||
|
||||
var s_length := s length. // Number of UTF-8 characters
|
||||
var ws_length := ws length. // Number of UTF-16 characters
|
||||
var u_length := ws toArray; length. //Number of UTF-32 characters
|
||||
].
|
||||
|
|
|
|||
|
|
@ -1,2 +1,10 @@
|
|||
#var s_byte_length := s toByteArray length. // Number of bytes
|
||||
#var ws_byte_length := ws toByteArray length. // Number of bytes
|
||||
import extensions.
|
||||
|
||||
program =
|
||||
[
|
||||
var s := "Hello, world!". // UTF-8 literal
|
||||
var ws := "Привет мир!"w. // UTF-16 literal
|
||||
|
||||
var s_byte_length := s toByteArray; length. // Number of bytes
|
||||
var ws_byte_length := ws toByteArray; length. // Number of bytes
|
||||
].
|
||||
|
|
|
|||
|
|
@ -1,19 +0,0 @@
|
|||
import java.text.BreakIterator;
|
||||
|
||||
public class Grapheme {
|
||||
public static void main(String[] args) {
|
||||
printLength("møøse");
|
||||
printLength("𝔘𝔫𝔦𝔠𝔬𝔡𝔢");
|
||||
printLength("J̲o̲s̲é̲");
|
||||
}
|
||||
|
||||
public static void printLength(String s) {
|
||||
BreakIterator it = BreakIterator.getCharacterInstance();
|
||||
it.setText(s);
|
||||
int count = 0;
|
||||
while (it.next() != BreakIterator.DONE) {
|
||||
count++;
|
||||
}
|
||||
System.out.println("Grapheme length: " + count+ " " + s);
|
||||
}
|
||||
}
|
||||
6
Task/String-length/Kotlin/string-length.kotlin
Normal file
6
Task/String-length/Kotlin/string-length.kotlin
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
// version 1.0.6
|
||||
fun main(args: Array<String>) {
|
||||
val s = "José"
|
||||
println("The char length is ${s.length}")
|
||||
println("The byte length is ${Character.BYTES * s.length}")
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
alias stringlength { echo -a Your Name is: $len($$?="Whats your name") letters long! }
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
alias utf8len { return $len($utfdecode($1)) }
|
||||
alias stringlength2 {
|
||||
var %name = Børje
|
||||
echo -a %name is: $utf8len(%name) characters long!
|
||||
}
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
var s: string = "Hello, world! ☺"
|
||||
echo '"',s, '"'," has byte length: ", len(s)
|
||||
|
||||
# -> "Hello, world! ☺" has unicode char length: 17
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
import unicode
|
||||
|
||||
var s: string = "Hello, world! ☺"
|
||||
echo '"',s, '"'," has unicode char length: ", runeLen(s)
|
||||
|
||||
# -> "Hello, world! ☺" has unicode char length: 15
|
||||
7
Task/String-length/Ol/string-length.ol
Normal file
7
Task/String-length/Ol/string-length.ol
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
; Character length
|
||||
(print (string-length "Hello, wørld!"))
|
||||
; ==> 13
|
||||
|
||||
; Byte (utf-8 encoded) length
|
||||
(print (length (string->bytes "Hello, wørld!")))
|
||||
; ==> 14
|
||||
|
|
@ -1 +0,0 @@
|
|||
$length = strlen('Hello, world!');
|
||||
|
|
@ -1 +0,0 @@
|
|||
$length = mb_strlen('Hello, world!', 'UTF-8'); // or whatever encoding
|
||||
|
|
@ -1 +0,0 @@
|
|||
$length = grapheme_strlen('Hello, world!'); // UTF-8 encoding required
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
input a$
|
||||
print len(a$)
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
puts "あいうえお".length
|
||||
# => 5
|
||||
|
||||
puts "あいうえお".size # alias for length
|
||||
# => 5
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
# -*- coding: iso-8859-1 -*-
|
||||
s = "møøse"
|
||||
puts "Byte length: %d" % s.bytesize
|
||||
puts "Character length: %d" % s.length
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
s = "møøse"
|
||||
puts "Byte length: %d" % s.bytesize
|
||||
puts "Character length: %d" % s.length
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
# -*- coding: gb18030 -*-
|
||||
s = "møøse"
|
||||
puts "Byte length: %d" % s.bytesize
|
||||
puts "Character length: %d" % s.length
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
class String
|
||||
# Define String#bytesize for Ruby 1.8.6.
|
||||
unless method_defined?(:bytesize)
|
||||
alias bytesize length
|
||||
end
|
||||
end
|
||||
|
||||
s = "文字化け"
|
||||
puts "Byte length: %d" % s.bytesize
|
||||
puts "Character length: %d" % s.gsub(/./u, ' ').size
|
||||
4
Task/String-length/Rust/string-length.rust
Normal file
4
Task/String-length/Rust/string-length.rust
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
fn main(){
|
||||
let len = String::from("Hello world").len();
|
||||
println!("{}", len);
|
||||
}
|
||||
24
Task/String-length/SPL/string-length.spl
Normal file
24
Task/String-length/SPL/string-length.spl
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
t = ["abc","J̲o̲s̲é̲","møøse","𝔘𝔫𝔦𝔠𝔬𝔡𝔢"]
|
||||
|
||||
> i, 1..#.size(t,1)
|
||||
? i>1, #.output()
|
||||
#.output(#.quot,t[i],#.quot," contains")
|
||||
|
||||
p = #.split(t[i])
|
||||
cn = #.size(p,1)
|
||||
s = #.str(cn,">3>")+" chars: "
|
||||
> j, 1..cn
|
||||
? j>1, s += ", "
|
||||
s += p[j]
|
||||
<
|
||||
#.output(s)
|
||||
|
||||
q = #.array(t[i])
|
||||
bn = #.size(q,1)
|
||||
s = #.str(bn,">3>")+" bytes: "
|
||||
> j, 1..bn
|
||||
? j>1, s += ", "
|
||||
s += #.str(q[j],"X2")+"h"
|
||||
<
|
||||
#.output(s)
|
||||
<
|
||||
14
Task/String-length/Simula/string-length-1.simula
Normal file
14
Task/String-length/Simula/string-length-1.simula
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
BEGIN
|
||||
TEXT LINE;
|
||||
WHILE NOT LASTITEM DO
|
||||
BEGIN
|
||||
INTEGER L;
|
||||
LINE :- COPY(SYSIN.IMAGE).STRIP;
|
||||
OUTCHAR('"');
|
||||
OUTTEXT(LINE);
|
||||
OUTCHAR('"');
|
||||
OUTTEXT(" BYTE LENGTH = "); OUTINT(LINE.LENGTH, 0);
|
||||
OUTIMAGE;
|
||||
INIMAGE;
|
||||
END;
|
||||
END.
|
||||
46
Task/String-length/Simula/string-length-2.simula
Normal file
46
Task/String-length/Simula/string-length-2.simula
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
BEGIN
|
||||
|
||||
! NUMBER OF UFT8 CHARACTERS IN STRING ;
|
||||
INTEGER PROCEDURE UTF8STRLEN(S); TEXT S;
|
||||
BEGIN
|
||||
INTEGER R, LEN, BYTES, ALLBYTES;
|
||||
CHARACTER BYTE;
|
||||
WHILE S.MORE DO
|
||||
BEGIN
|
||||
BYTE := S.GETCHAR;
|
||||
ALLBYTES := ALLBYTES + 1;
|
||||
R := RANK(BYTE);
|
||||
LEN := LEN + 1;
|
||||
BYTES :=
|
||||
IF R >= 0 AND R <= 127 THEN 1 ELSE ! 0....... ASCII ;
|
||||
IF R >= 128 AND R <= 191 THEN 0 ELSE ! 10...... CONTINUATION ;
|
||||
IF R >= 192 AND R <= 223 THEN 2 ELSE ! 110..... 10x ;
|
||||
IF R >= 224 AND R <= 239 THEN 3 ELSE ! 1110.... 10x 10x ;
|
||||
IF R >= 240 AND R <= 247 THEN 4 ELSE ! 11110... 10x 10x 10x ;
|
||||
-1;
|
||||
IF BYTES = -1 THEN ERROR("ILLEGAL UTF8 STRING");
|
||||
WHILE BYTES > 1 DO
|
||||
BEGIN
|
||||
BYTE := S.GETCHAR;
|
||||
ALLBYTES := ALLBYTES + 1;
|
||||
BYTES := BYTES - 1;
|
||||
END;
|
||||
END;
|
||||
UTF8STRLEN := LEN;
|
||||
END UTF8STRLEN;
|
||||
|
||||
TEXT LINE;
|
||||
WHILE NOT LASTITEM DO
|
||||
BEGIN
|
||||
INTEGER L;
|
||||
LINE :- COPY(SYSIN.IMAGE).STRIP;
|
||||
OUTCHAR('"');
|
||||
OUTTEXT(LINE);
|
||||
OUTCHAR('"');
|
||||
L := UTF8STRLEN(LINE);
|
||||
OUTTEXT(" CHARACTER LENGTH = "); OUTINT(UTF8STRLEN(LINE), 0);
|
||||
OUTIMAGE;
|
||||
INIMAGE;
|
||||
END;
|
||||
|
||||
END.
|
||||
3
Task/String-length/Stata/string-length.stata
Normal file
3
Task/String-length/Stata/string-length.stata
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
scalar s="Ἐν ἀρχῇ ἐποίησεν ὁ θεὸς τὸν οὐρανὸν καὶ τὴν γῆν"
|
||||
di strlen(s)
|
||||
di ustrlen(s)
|
||||
24
Task/String-length/X86-Assembly/string-length.x86
Normal file
24
Task/String-length/X86-Assembly/string-length.x86
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
.data
|
||||
string: .asciz "Test"
|
||||
|
||||
.text
|
||||
.globl main
|
||||
|
||||
main:
|
||||
pushl %ebp
|
||||
movl %esp, %ebp
|
||||
|
||||
pushl %edi
|
||||
xorb %al, %al
|
||||
movl $-1, %ecx
|
||||
movl $string, %edi
|
||||
cld
|
||||
repne scasb
|
||||
not %ecx
|
||||
dec %ecx
|
||||
popl %edi
|
||||
|
||||
;; string length is stored in %ecx register
|
||||
|
||||
leave
|
||||
ret
|
||||
1
Task/String-length/XTalk/string-length-1.xtalk
Normal file
1
Task/String-length/XTalk/string-length-1.xtalk
Normal file
|
|
@ -0,0 +1 @@
|
|||
put the length of "Hello World"
|
||||
1
Task/String-length/XTalk/string-length-2.xtalk
Normal file
1
Task/String-length/XTalk/string-length-2.xtalk
Normal file
|
|
@ -0,0 +1 @@
|
|||
put the number of characters in "Hello World"
|
||||
1
Task/String-length/XTalk/string-length-3.xtalk
Normal file
1
Task/String-length/XTalk/string-length-3.xtalk
Normal file
|
|
@ -0,0 +1 @@
|
|||
put the length of "Hello World"
|
||||
1
Task/String-length/XTalk/string-length-4.xtalk
Normal file
1
Task/String-length/XTalk/string-length-4.xtalk
Normal file
|
|
@ -0,0 +1 @@
|
|||
put the number of characters in "Hello World"
|
||||
2
Task/String-length/Zkl/string-length-1.zkl
Normal file
2
Task/String-length/Zkl/string-length-1.zkl
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
"abc".len() //-->3
|
||||
"\ufeff\u00A2 \u20ac".len() //-->9 "BOM¢ €"
|
||||
5
Task/String-length/Zkl/string-length-2.zkl
Normal file
5
Task/String-length/Zkl/string-length-2.zkl
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
"abc".len() //-->3
|
||||
"\ufeff\u00A2 \u20ac".len() //-->9
|
||||
Data(0,Int,"\ufeff\u00A2 \u20ac") //-->Data(9) (bytes)
|
||||
"J\u0332o\u0332s\u0332e\u0301\u0332".len() //-->14
|
||||
"\U1D518;\U1D52B;\U1D526;\U1D520;\U1D52C;\U1D521;\U1D522;".len() //-->28
|
||||
6
Task/String-length/Zkl/string-length-3.zkl
Normal file
6
Task/String-length/Zkl/string-length-3.zkl
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
"abc".len(8) //-->3
|
||||
"\ufeff\u00A2 \u20ac".len(8) //-->4 "BOM¢ €"
|
||||
"\U1000;".len(8) //-->Exception thrown: ValueError(Invalid UTF-8 string)
|
||||
"\uD800" //-->SyntaxError : Line 2: Bad Unicode constant (\uD800-\uDFFF)
|
||||
"J\u0332o\u0332s\u0332e\u0301\u0332".len(8) //-->9 "J̲o̲s̲é̲"
|
||||
"\U1D518;\U1D52B;\U1D526;\U1D520;\U1D52C;\U1D521;\U1D522;".len(8) //-->7 "𝔘𝔫𝔦𝔠𝔬𝔡𝔢"
|
||||
Loading…
Add table
Add a link
Reference in a new issue