Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
5
Task/String-length/00-META.yaml
Normal file
5
Task/String-length/00-META.yaml
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
category:
|
||||
- String manipulation
|
||||
from: http://rosettacode.org/wiki/String_length
|
||||
note: Basic language learning
|
||||
23
Task/String-length/00-TASK.txt
Normal file
23
Task/String-length/00-TASK.txt
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
;Task:
|
||||
Find the <em>character</em> and <em>byte</em> length of a string.
|
||||
|
||||
This means encodings like [[UTF-8]] need to be handled properly, as there is not necessarily a one-to-one relationship between bytes and characters.
|
||||
|
||||
By ''character'', we mean an individual Unicode ''code point'', not a user-visible ''grapheme'' containing combining characters.
|
||||
|
||||
For example, the character length of "møøse" is 5 but the byte length is 7 in UTF-8 and 10 in UTF-16.
|
||||
|
||||
Non-BMP code points (those between 0x10000 and 0x10FFFF) must also be handled correctly: answers should produce actual character counts in code points, not in code unit counts.
|
||||
|
||||
Therefore a string like "𝔘𝔫𝔦𝔠𝔬𝔡𝔢" (consisting of the 7 Unicode characters U+1D518 U+1D52B U+1D526 U+1D520 U+1D52C U+1D521 U+1D522) is 7 characters long, '''not''' 14 UTF-16 code units; and it is 28 bytes long whether encoded in UTF-8 or in UTF-16.
|
||||
|
||||
Please mark your examples with <nowiki>===Character Length=== or ===Byte Length===</nowiki>.
|
||||
|
||||
If your language is capable of providing the string length in graphemes, mark those examples with <nowiki>===Grapheme Length===</nowiki>.
|
||||
|
||||
For example, the string "J̲o̲s̲é̲" ("J\x{332}o\x{332}s\x{332}e\x{301}\x{332}") has 4 user-visible graphemes, 9 characters (code points), and 14 bytes when encoded in UTF-8.
|
||||
<br><br>
|
||||
|
||||
{{Template:Strings}}
|
||||
<br><br>
|
||||
|
||||
25
Task/String-length/360-Assembly/string-length.360
Normal file
25
Task/String-length/360-Assembly/string-length.360
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
* String length 06/07/2016
|
||||
LEN CSECT
|
||||
USING LEN,15 base register
|
||||
LA 1,L'C length of C
|
||||
XDECO 1,PG
|
||||
XPRNT PG,12
|
||||
LA 1,L'H length of H
|
||||
XDECO 1,PG
|
||||
XPRNT PG,12
|
||||
LA 1,L'F length of F
|
||||
XDECO 1,PG
|
||||
XPRNT PG,12
|
||||
LA 1,L'D length of D
|
||||
XDECO 1,PG
|
||||
XPRNT PG,12
|
||||
LA 1,L'PG length of PG
|
||||
XDECO 1,PG
|
||||
XPRNT PG,12
|
||||
BR 14 exit length
|
||||
C DS C character 1
|
||||
H DS H half word 2
|
||||
F DS F full word 4
|
||||
D DS D double word 8
|
||||
PG DS CL12 string 12
|
||||
END LEN
|
||||
1
Task/String-length/4D/string-length.4d
Normal file
1
Task/String-length/4D/string-length.4d
Normal file
|
|
@ -0,0 +1 @@
|
|||
$length:=Length("Hello, world!")
|
||||
12
Task/String-length/6502-Assembly/string-length.6502
Normal file
12
Task/String-length/6502-Assembly/string-length.6502
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
GetStringLength: ;$00 and $01 make up the pointer to the string's base address.
|
||||
;(Of course, any two consecutive zero-page memory locations can fulfill this role.)
|
||||
LDY #0 ;Y is both the index into the string and the length counter.
|
||||
|
||||
loop_getStringLength:
|
||||
LDA ($00),y
|
||||
BEQ exit
|
||||
INY
|
||||
JMP loop_getStringLength
|
||||
|
||||
exit:
|
||||
RTS ;string length is now loaded into Y.
|
||||
15
Task/String-length/68000-Assembly/string-length.68000
Normal file
15
Task/String-length/68000-Assembly/string-length.68000
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
GetStringLength:
|
||||
; INPUT: A3 = BASE ADDRESS OF STRING
|
||||
; RETURNS LENGTH IN D1 (MEASURED IN BYTES)
|
||||
MOVE.L #0,D1
|
||||
|
||||
loop_getStringLength:
|
||||
|
||||
MOVE.B (A3)+,D0
|
||||
CMP #0,D0
|
||||
BEQ done
|
||||
ADDQ.L #1,D1
|
||||
BRA loop_getStringLength
|
||||
|
||||
done:
|
||||
RTS
|
||||
15
Task/String-length/8086-Assembly/string-length.8086
Normal file
15
Task/String-length/8086-Assembly/string-length.8086
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
;INPUT: DS:SI = BASE ADDR. OF STRING
|
||||
;TYPICALLY, MS-DOS USES $ TO TERMINATE STRINGS.
|
||||
GetStringLength:
|
||||
xor cx,cx ;this takes fewer bytes to encode than "mov cx,0"
|
||||
cld ;makes string functions post-inc rather than post-dec.
|
||||
|
||||
loop_GetStringLength:
|
||||
lodsb ;equivalent of "mov al,[ds:si],inc si" except this doesn't alter the flags.
|
||||
cmp '$'
|
||||
je done ;if equal, we're finished.
|
||||
inc cx ;add 1 to length counter. A null string will have a length of zero.
|
||||
jmp loop_GetStringLength
|
||||
|
||||
done:
|
||||
ret
|
||||
98
Task/String-length/AArch64-Assembly/string-length.aarch64
Normal file
98
Task/String-length/AArch64-Assembly/string-length.aarch64
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
/* ARM assembly AARCH64 Raspberry PI 3B */
|
||||
/* program stringLength64.s */
|
||||
|
||||
/*******************************************/
|
||||
/* Constantes file */
|
||||
/*******************************************/
|
||||
/* for this file see task include a file in language AArch64 assembly*/
|
||||
.include "../includeConstantesARM64.inc"
|
||||
|
||||
/*********************************/
|
||||
/* Initialized data */
|
||||
/*********************************/
|
||||
.data
|
||||
sMessResultByte: .asciz "===Byte Length=== : @ \n"
|
||||
sMessResultChar: .asciz "===Character Length=== : @ \n"
|
||||
szString1: .asciz "møøse€"
|
||||
szCarriageReturn: .asciz "\n"
|
||||
|
||||
/*********************************/
|
||||
/* UnInitialized data */
|
||||
/*********************************/
|
||||
.bss
|
||||
sZoneConv: .skip 24
|
||||
/*********************************/
|
||||
/* code section */
|
||||
/*********************************/
|
||||
.text
|
||||
.global main
|
||||
main: // entry of program
|
||||
ldr x0,qAdrszString1
|
||||
bl affichageMess // display string
|
||||
ldr x0,qAdrszCarriageReturn
|
||||
bl affichageMess
|
||||
|
||||
ldr x0,qAdrszString1
|
||||
mov x1,#0
|
||||
1: // loop compute length bytes
|
||||
ldrb w2,[x0,x1]
|
||||
cmp w2,#0
|
||||
cinc x1,x1,ne
|
||||
bne 1b
|
||||
|
||||
mov x0,x1 // result display
|
||||
ldr x1,qAdrsZoneConv
|
||||
bl conversion10 // call decimal conversion
|
||||
ldr x0,qAdrsMessResultByte
|
||||
ldr x1,qAdrsZoneConv // insert conversion in message
|
||||
bl strInsertAtCharInc
|
||||
bl affichageMess
|
||||
|
||||
ldr x0,qAdrszString1
|
||||
mov x1,#0
|
||||
mov x3,#0
|
||||
2: // loop compute length characters
|
||||
ldrb w2,[x0,x1]
|
||||
cmp w2,#0
|
||||
beq 6f
|
||||
and x2,x2,#0b11100000 // 3 bytes ?
|
||||
cmp x2,#0b11100000
|
||||
bne 3f
|
||||
add x3,x3,#1
|
||||
add x1,x1,#3
|
||||
b 2b
|
||||
3:
|
||||
and x2,x2,#0b11000000 // 2 bytes ?
|
||||
cmp x2,#0b11000000
|
||||
bne 4f
|
||||
add x3,x3,#1
|
||||
add x1,x1,#2
|
||||
b 2b
|
||||
4: // else 1 byte
|
||||
add x3,x3,#1
|
||||
add x1,x1,#1
|
||||
b 2b
|
||||
|
||||
6:
|
||||
mov x0,x3
|
||||
ldr x1,qAdrsZoneConv
|
||||
bl conversion10 // call decimal conversion
|
||||
ldr x0,qAdrsMessResultChar
|
||||
ldr x1,qAdrsZoneConv // insert conversion in message
|
||||
bl strInsertAtCharInc
|
||||
bl affichageMess
|
||||
100: // standard end of the program
|
||||
mov x0,0 // return code
|
||||
mov x8,EXIT // request to exit program
|
||||
svc 0 // perform the system call
|
||||
|
||||
qAdrszCarriageReturn: .quad szCarriageReturn
|
||||
qAdrsMessResultByte: .quad sMessResultByte
|
||||
qAdrsMessResultChar: .quad sMessResultChar
|
||||
qAdrszString1: .quad szString1
|
||||
qAdrsZoneConv: .quad sZoneConv
|
||||
/********************************************************/
|
||||
/* File Include fonctions */
|
||||
/********************************************************/
|
||||
/* for this file see task include a file in language AArch64 assembly */
|
||||
.include "../includeARM64.inc"
|
||||
7
Task/String-length/ALGOL-68/string-length-1.alg
Normal file
7
Task/String-length/ALGOL-68/string-length-1.alg
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
BITS bits := bits pack((TRUE, TRUE, FALSE, FALSE)); # packed array of BOOL #
|
||||
BYTES bytes := bytes pack("Hello, world"); # packed array of CHAR #
|
||||
print((
|
||||
"BITS and BYTES are fixed width:", new line,
|
||||
"bits width:", bits width, ", max bits: ", max bits, ", bits:", bits, new line,
|
||||
"bytes width: ",bytes width, ", UPB:",UPB STRING(bytes), ", string:", STRING(bytes),"!", new line
|
||||
))
|
||||
7
Task/String-length/ALGOL-68/string-length-2.alg
Normal file
7
Task/String-length/ALGOL-68/string-length-2.alg
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
STRING str := "hello, world";
|
||||
INT length := UPB str;
|
||||
printf(($"Length of """g""" is "g(3)l$,str,length));
|
||||
|
||||
printf(($l"STRINGS can start at -1, in which case LWB must be used:"l$));
|
||||
STRING s := "abcd"[@-1];
|
||||
print(("s:",s, ", LWB:", LWB s, ", UPB:",UPB s, ", LEN:",UPB s - LWB s + 1))
|
||||
102
Task/String-length/ARM-Assembly/string-length.arm
Normal file
102
Task/String-length/ARM-Assembly/string-length.arm
Normal file
|
|
@ -0,0 +1,102 @@
|
|||
/* ARM assembly Raspberry PI */
|
||||
/* program stringLength.s */
|
||||
|
||||
/* REMARK 1 : this program use routines in a include file
|
||||
see task Include a file language arm assembly
|
||||
for the routine affichageMess conversion10
|
||||
see at end of this program the instruction include */
|
||||
/* for constantes see task include a file in arm assembly */
|
||||
/************************************/
|
||||
/* Constantes */
|
||||
/************************************/
|
||||
.include "../constantes.inc"
|
||||
|
||||
/*********************************/
|
||||
/* Initialized data */
|
||||
/*********************************/
|
||||
.data
|
||||
sMessResultByte: .asciz "===Byte Length=== : @ \n"
|
||||
sMessResultChar: .asciz "===Character Length=== : @ \n"
|
||||
szString1: .asciz "møøse€"
|
||||
szCarriageReturn: .asciz "\n"
|
||||
|
||||
|
||||
/*********************************/
|
||||
/* UnInitialized data */
|
||||
/*********************************/
|
||||
.bss
|
||||
sZoneConv: .skip 24
|
||||
/*********************************/
|
||||
/* code section */
|
||||
/*********************************/
|
||||
.text
|
||||
.global main
|
||||
main: @ entry of program
|
||||
ldr r0,iAdrszString1
|
||||
bl affichageMess @ display string
|
||||
ldr r0,iAdrszCarriageReturn
|
||||
bl affichageMess
|
||||
|
||||
ldr r0,iAdrszString1
|
||||
mov r1,#0
|
||||
1: @ loop compute length bytes
|
||||
ldrb r2,[r0,r1]
|
||||
cmp r2,#0
|
||||
addne r1,#1
|
||||
bne 1b
|
||||
|
||||
mov r0,r1 @ result display
|
||||
ldr r1,iAdrsZoneConv
|
||||
bl conversion10 @ call decimal conversion
|
||||
ldr r0,iAdrsMessResultByte
|
||||
ldr r1,iAdrsZoneConv @ insert conversion in message
|
||||
bl strInsertAtCharInc
|
||||
bl affichageMess
|
||||
|
||||
ldr r0,iAdrszString1
|
||||
mov r1,#0
|
||||
mov r3,#0
|
||||
2: @ loop compute length characters
|
||||
ldrb r2,[r0,r1]
|
||||
cmp r2,#0
|
||||
beq 6f
|
||||
and r2,#0b11100000 @ 3 bytes ?
|
||||
cmp r2,#0b11100000
|
||||
bne 3f
|
||||
add r3,#1
|
||||
add r1,#3
|
||||
b 2b
|
||||
3:
|
||||
and r2,#0b11000000 @ 2 bytes ?
|
||||
cmp r2,#0b11000000
|
||||
bne 4f
|
||||
add r3,#1
|
||||
add r1,#2
|
||||
b 2b
|
||||
4: @ else 1 byte
|
||||
add r3,#1
|
||||
add r1,#1
|
||||
b 2b
|
||||
|
||||
6:
|
||||
mov r0,r3
|
||||
ldr r1,iAdrsZoneConv
|
||||
bl conversion10 @ call decimal conversion
|
||||
ldr r0,iAdrsMessResultChar
|
||||
ldr r1,iAdrsZoneConv @ insert conversion in message
|
||||
bl strInsertAtCharInc
|
||||
bl affichageMess
|
||||
100: @ standard end of the program
|
||||
mov r0, #0 @ return code
|
||||
mov r7, #EXIT @ request to exit program
|
||||
svc #0 @ perform the system call
|
||||
|
||||
iAdrszCarriageReturn: .int szCarriageReturn
|
||||
iAdrsMessResultByte: .int sMessResultByte
|
||||
iAdrsMessResultChar: .int sMessResultChar
|
||||
iAdrszString1: .int szString1
|
||||
iAdrsZoneConv: .int sZoneConv
|
||||
/***************************************************/
|
||||
/* ROUTINES INCLUDE */
|
||||
/***************************************************/
|
||||
.include "../affichage.inc"
|
||||
4
Task/String-length/AWK/string-length-1.awk
Normal file
4
Task/String-length/AWK/string-length-1.awk
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
w=length("Hello, world!") # static string example
|
||||
x=length("Hello," s " world!") # dynamic string example
|
||||
y=length($1) # input field example
|
||||
z=length(s) # variable name example
|
||||
2
Task/String-length/AWK/string-length-2.awk
Normal file
2
Task/String-length/AWK/string-length-2.awk
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
#!/usr/bin/awk -f
|
||||
{print"The length of this line is "length($0)}
|
||||
8
Task/String-length/Action-/string-length.action
Normal file
8
Task/String-length/Action-/string-length.action
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
PROC Test(CHAR ARRAY s)
|
||||
PrintF("Length of ""%S"" is %B%E",s,s(0))
|
||||
RETURN
|
||||
|
||||
PROC Main()
|
||||
Test("Hello world!")
|
||||
Test("")
|
||||
RETURN
|
||||
34
Task/String-length/ActionScript/string-length-1.as
Normal file
34
Task/String-length/ActionScript/string-length-1.as
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
package {
|
||||
|
||||
import flash.display.Sprite;
|
||||
import flash.events.Event;
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
public class StringByteLength extends Sprite {
|
||||
|
||||
public function StringByteLength() {
|
||||
if ( stage ) _init();
|
||||
else addEventListener(Event.ADDED_TO_STAGE, _init);
|
||||
}
|
||||
|
||||
private function _init(e:Event = null):void {
|
||||
var s1:String = "The quick brown fox jumps over the lazy dog";
|
||||
var s2:String = "𝔘𝔫𝔦𝔠𝔬𝔡𝔢";
|
||||
var s3:String = "José";
|
||||
|
||||
var b:ByteArray = new ByteArray();
|
||||
b.writeUTFBytes(s1);
|
||||
trace(b.length); // 43
|
||||
|
||||
b.clear();
|
||||
b.writeUTFBytes(s2);
|
||||
trace(b.length); // 28
|
||||
|
||||
b.clear();
|
||||
b.writeUTFBytes(s3);
|
||||
trace(b.length); // 5
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
4
Task/String-length/ActionScript/string-length-2.as
Normal file
4
Task/String-length/ActionScript/string-length-2.as
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
var s1:String = "The quick brown fox jumps over the lazy dog";
|
||||
var s2:String = "𝔘𝔫𝔦𝔠𝔬𝔡𝔢";
|
||||
var s3:String = "José";
|
||||
trace(s1.length, s2.length, s3.length); // 43, 14, 4
|
||||
2
Task/String-length/Ada/string-length-1.ada
Normal file
2
Task/String-length/Ada/string-length-1.ada
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
Str : String := "Hello World";
|
||||
Length : constant Natural := Str'Size / 8;
|
||||
6
Task/String-length/Ada/string-length-2.ada
Normal file
6
Task/String-length/Ada/string-length-2.ada
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
Latin_1_Str : String := "Hello World";
|
||||
UCS_16_Str : Wide_String := "Hello World";
|
||||
Unicode_Str : Wide_Wide_String := "Hello World";
|
||||
Latin_1_Length : constant Natural := Latin_1_Str'Length;
|
||||
UCS_16_Length : constant Natural := UCS_16_Str'Length;
|
||||
Unicode_Length : constant Natural := Unicode_Str'Length;
|
||||
1
Task/String-length/Aime/string-length-1.aime
Normal file
1
Task/String-length/Aime/string-length-1.aime
Normal file
|
|
@ -0,0 +1 @@
|
|||
length("Hello, World!")
|
||||
1
Task/String-length/Aime/string-length-2.aime
Normal file
1
Task/String-length/Aime/string-length-2.aime
Normal file
|
|
@ -0,0 +1 @@
|
|||
~"Hello, World!"
|
||||
2
Task/String-length/Apex/string-length.apex
Normal file
2
Task/String-length/Apex/string-length.apex
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
String myString = 'abcd';
|
||||
System.debug('Size of String', myString.length());
|
||||
|
|
@ -0,0 +1 @@
|
|||
count of "Hello World"
|
||||
32
Task/String-length/AppleScript/string-length-2.applescript
Normal file
32
Task/String-length/AppleScript/string-length-2.applescript
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
set inString to "Hello é̦世界"
|
||||
set byteCount to 0
|
||||
|
||||
repeat with c in inString
|
||||
set t to id of c
|
||||
if ((count of t) > 0) then
|
||||
repeat with i in t
|
||||
set byteCount to byteCount + doit(i)
|
||||
end repeat
|
||||
else
|
||||
set byteCount to byteCount + doit(t)
|
||||
end if
|
||||
end repeat
|
||||
|
||||
byteCount
|
||||
|
||||
on doit(cid)
|
||||
set n to (cid as integer)
|
||||
if n > 67108863 then -- 0x3FFFFFF
|
||||
return 6
|
||||
else if n > 2097151 then -- 0x1FFFFF
|
||||
return 5
|
||||
else if n > 65535 then -- 0xFFFF
|
||||
return 4
|
||||
else if n > 2047 then -- 0x07FF
|
||||
return 3
|
||||
else if n > 127 then -- 0x7F
|
||||
return 2
|
||||
else
|
||||
return 1
|
||||
end if
|
||||
end doit
|
||||
|
|
@ -0,0 +1 @@
|
|||
count of "Hello World"
|
||||
|
|
@ -0,0 +1 @@
|
|||
count "Hello World"
|
||||
1
Task/String-length/Applesoft-BASIC/string-length.basic
Normal file
1
Task/String-length/Applesoft-BASIC/string-length.basic
Normal file
|
|
@ -0,0 +1 @@
|
|||
? LEN("HELLO, WORLD!")
|
||||
3
Task/String-length/Arturo/string-length.arturo
Normal file
3
Task/String-length/Arturo/string-length.arturo
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
str: "Hello World"
|
||||
|
||||
print ["length =" size str]
|
||||
1
Task/String-length/AutoHotkey/string-length-1.ahk
Normal file
1
Task/String-length/AutoHotkey/string-length-1.ahk
Normal file
|
|
@ -0,0 +1 @@
|
|||
Msgbox % StrLen("Hello World")
|
||||
3
Task/String-length/AutoHotkey/string-length-2.ahk
Normal file
3
Task/String-length/AutoHotkey/string-length-2.ahk
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
String := "Hello World"
|
||||
StringLen, Length, String
|
||||
Msgbox % Length
|
||||
1
Task/String-length/Avail/string-length-1.avail
Normal file
1
Task/String-length/Avail/string-length-1.avail
Normal file
|
|
@ -0,0 +1 @@
|
|||
|"møøse"|
|
||||
7
Task/String-length/Avail/string-length-2.avail
Normal file
7
Task/String-length/Avail/string-length-2.avail
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
nonBMPString ::= "𝔘𝔫𝔦𝔠𝔬𝔡𝔢";
|
||||
encoder ::= a UTF8 encoder;
|
||||
bytes ::= encoder process nonBMPString;
|
||||
|bytes|
|
||||
|
||||
// or, as a one-liner
|
||||
|a UTF8 encoder process "𝔘𝔫𝔦𝔠𝔬𝔡𝔢"|
|
||||
2
Task/String-length/Axe/string-length.axe
Normal file
2
Task/String-length/Axe/string-length.axe
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
"HELLO, WORLD"→Str1
|
||||
Disp length(Str1)▶Dec,i
|
||||
2
Task/String-length/BASIC/string-length.basic
Normal file
2
Task/String-length/BASIC/string-length.basic
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
INPUT a$
|
||||
PRINT LEN(a$)
|
||||
2
Task/String-length/BBC-BASIC/string-length-1.basic
Normal file
2
Task/String-length/BBC-BASIC/string-length-1.basic
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
INPUT text$
|
||||
PRINT LEN(text$)
|
||||
12
Task/String-length/BBC-BASIC/string-length-2.basic
Normal file
12
Task/String-length/BBC-BASIC/string-length-2.basic
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
CP_ACP = 0
|
||||
CP_UTF8 = &FDE9
|
||||
|
||||
textA$ = "møøse"
|
||||
textW$ = " "
|
||||
textU$ = " "
|
||||
|
||||
SYS "MultiByteToWideChar", CP_ACP, 0, textA$, -1, !^textW$, LEN(textW$)/2 TO nW%
|
||||
SYS "WideCharToMultiByte", CP_UTF8, 0, textW$, -1, !^textU$, LEN(textU$), 0, 0
|
||||
PRINT "Length in bytes (ANSI encoding) = " ; LEN(textA$)
|
||||
PRINT "Length in bytes (UTF-16 encoding) = " ; 2*(nW%-1)
|
||||
PRINT "Length in bytes (UTF-8 encoding) = " ; LEN($$!^textU$)
|
||||
1
Task/String-length/BQN/string-length-1.bqn
Normal file
1
Task/String-length/BQN/string-length-1.bqn
Normal file
|
|
@ -0,0 +1 @@
|
|||
BLen ← {(≠𝕩)+´⥊𝕩≥⌜@+128‿2048‿65536}
|
||||
1
Task/String-length/BQN/string-length-2.bqn
Normal file
1
Task/String-length/BQN/string-length-2.bqn
Normal file
|
|
@ -0,0 +1 @@
|
|||
Len ← ≠
|
||||
5
Task/String-length/BQN/string-length-3.bqn
Normal file
5
Task/String-length/BQN/string-length-3.bqn
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
•Show >(⊢⋈⊸∾Len⋈BLen)¨⟨
|
||||
"møøse"
|
||||
"𝔘𝔫𝔦𝔠𝔬𝔡𝔢"
|
||||
"J̲o̲s̲é̲"
|
||||
⟩
|
||||
5
Task/String-length/BQN/string-length-4.bqn
Normal file
5
Task/String-length/BQN/string-length-4.bqn
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
┌─
|
||||
╵ "møøse" 5 7
|
||||
"𝔘𝔫𝔦𝔠𝔬𝔡𝔢" 7 28
|
||||
"J̲o̲s̲é̲" 8 13
|
||||
┘
|
||||
8
Task/String-length/BaCon/string-length.bacon
Normal file
8
Task/String-length/BaCon/string-length.bacon
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
PRINT "Bytelen of 'hello': ", LEN("hello")
|
||||
PRINT "Charlen of 'hello': ", ULEN("hello")
|
||||
|
||||
PRINT "Bytelen of 'møøse': ", LEN("møøse")
|
||||
PRINT "Charlen of 'møøse': ", ULEN("møøse")
|
||||
|
||||
PRINT "Bytelen of '𝔘𝔫𝔦𝔠𝔬𝔡𝔢': ", LEN("𝔘𝔫𝔦𝔠𝔬𝔡𝔢")
|
||||
PRINT "Charlen of '𝔘𝔫𝔦𝔠𝔬𝔡𝔢': ", ULEN("𝔘𝔫𝔦𝔠𝔬𝔡𝔢")
|
||||
17
Task/String-length/Batch-File/string-length.bat
Normal file
17
Task/String-length/Batch-File/string-length.bat
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
@echo off
|
||||
setlocal enabledelayedexpansion
|
||||
call :length %1 res
|
||||
echo length of %1 is %res%
|
||||
goto :eof
|
||||
|
||||
:length
|
||||
set str=%~1
|
||||
set cnt=0
|
||||
:loop
|
||||
if "%str%" equ "" (
|
||||
set %2=%cnt%
|
||||
goto :eof
|
||||
)
|
||||
set str=!str:~1!
|
||||
set /a cnt = cnt + 1
|
||||
goto loop
|
||||
7
Task/String-length/Bracmat/string-length-1.bracmat
Normal file
7
Task/String-length/Bracmat/string-length-1.bracmat
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
(ByteLength=
|
||||
length
|
||||
. @(!arg:? [?length)
|
||||
& !length
|
||||
);
|
||||
|
||||
out$ByteLength$𝔘𝔫𝔦𝔠𝔬𝔡𝔢
|
||||
16
Task/String-length/Bracmat/string-length-2.bracmat
Normal file
16
Task/String-length/Bracmat/string-length-2.bracmat
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
(CharacterLength=
|
||||
length c
|
||||
. 0:?length
|
||||
& @( !arg
|
||||
: ?
|
||||
( %?c
|
||||
& utf$!c:?k
|
||||
& 1+!length:?length
|
||||
& ~
|
||||
)
|
||||
?
|
||||
)
|
||||
| !length
|
||||
);
|
||||
|
||||
out$CharacterLength$𝔘𝔫𝔦𝔠𝔬𝔡𝔢
|
||||
14
Task/String-length/Bracmat/string-length-3.bracmat
Normal file
14
Task/String-length/Bracmat/string-length-3.bracmat
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
(CharacterLength=
|
||||
length c p
|
||||
. 0:?length:?p
|
||||
& @( !arg
|
||||
: ?
|
||||
( [!p %?c
|
||||
& utf$!c:?k
|
||||
& 1+!length:?length
|
||||
)
|
||||
([?p&~)
|
||||
?
|
||||
)
|
||||
| !length
|
||||
);
|
||||
4
Task/String-length/Bracmat/string-length-4.bracmat
Normal file
4
Task/String-length/Bracmat/string-length-4.bracmat
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
(CharacterLength=
|
||||
length
|
||||
. vap$((=.!arg).!arg):? [?length&!length
|
||||
);
|
||||
6
Task/String-length/Brainf---/string-length.bf
Normal file
6
Task/String-length/Brainf---/string-length.bf
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
,----- ----- [>,----- -----] ; read a text until a newline
|
||||
<[+++++ +++++<] ; restore the original text
|
||||
>[[-]<[>+<-]>+>]< ; add one to the accumulator cell for every byte read
|
||||
;; from esolang dot org
|
||||
>[-]>[-]+>[-]+< [>[-<-<<[->+>+<<]>[-<+>]>>]++++++++++>[-]+>[-]>[-]> [-]<<<<<[->-[>+>>]>[[-<+>]+>+>>]<<<<<]>>-[-<<+>>]<[-]++++++++ [-<++++++>]>>[-<<+>>]<<] <[.[-]<]
|
||||
[-]+++++ +++++. ; print newline
|
||||
11
Task/String-length/C++/string-length-1.cpp
Normal file
11
Task/String-length/C++/string-length-1.cpp
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
#include <string> // (not <string.h>!)
|
||||
using std::string;
|
||||
|
||||
int main()
|
||||
{
|
||||
string s = "Hello, world!";
|
||||
string::size_type length = s.length(); // option 1: In Characters/Bytes
|
||||
string::size_type size = s.size(); // option 2: In Characters/Bytes
|
||||
// In bytes same as above since sizeof(char) == 1
|
||||
string::size_type bytes = s.length() * sizeof(string::value_type);
|
||||
}
|
||||
8
Task/String-length/C++/string-length-2.cpp
Normal file
8
Task/String-length/C++/string-length-2.cpp
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#include <string>
|
||||
using std::wstring;
|
||||
|
||||
int main()
|
||||
{
|
||||
wstring s = L"\u304A\u306F\u3088\u3046";
|
||||
wstring::size_type length = s.length() * sizeof(wstring::value_type); // in bytes
|
||||
}
|
||||
8
Task/String-length/C++/string-length-3.cpp
Normal file
8
Task/String-length/C++/string-length-3.cpp
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#include <string>
|
||||
using std::wstring;
|
||||
|
||||
int main()
|
||||
{
|
||||
wstring s = L"\u304A\u306F\u3088\u3046";
|
||||
wstring::size_type length = s.length();
|
||||
}
|
||||
9
Task/String-length/C++/string-length-4.cpp
Normal file
9
Task/String-length/C++/string-length-4.cpp
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
#include <iostream>
|
||||
#include <codecvt>
|
||||
int main()
|
||||
{
|
||||
std::string utf8 = "\x7a\xc3\x9f\xe6\xb0\xb4\xf0\x9d\x84\x8b"; // U+007a, U+00df, U+6c34, U+1d10b
|
||||
std::cout << "Byte length: " << utf8.size() << '\n';
|
||||
std::wstring_convert<std::codecvt_utf8<char32_t>, char32_t> conv;
|
||||
std::cout << "Character length: " << conv.from_bytes(utf8).size() << '\n';
|
||||
}
|
||||
37
Task/String-length/C++/string-length-5.cpp
Normal file
37
Task/String-length/C++/string-length-5.cpp
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
#include <cwchar> // for mbstate_t
|
||||
#include <locale>
|
||||
|
||||
// give the character length for a given named locale
|
||||
std::size_t char_length(std::string const& text, char const* locale_name)
|
||||
{
|
||||
// locales work on pointers; get length and data from string and
|
||||
// then don't touch the original string any more, to avoid
|
||||
// invalidating the data pointer
|
||||
std::size_t len = text.length();
|
||||
char const* input = text.data();
|
||||
|
||||
// get the named locale
|
||||
std::locale loc(locale_name);
|
||||
|
||||
// get the conversion facet of the locale
|
||||
typedef std::codecvt<wchar_t, char, std::mbstate_t> cvt_type;
|
||||
cvt_type const& cvt = std::use_facet<cvt_type>(loc);
|
||||
|
||||
// allocate buffer for conversion destination
|
||||
std::size_t bufsize = cvt.max_length()*len;
|
||||
wchar_t* destbuf = new wchar_t[bufsize];
|
||||
wchar_t* dest_end;
|
||||
|
||||
// do the conversion
|
||||
mbstate_t state = mbstate_t();
|
||||
cvt.in(state, input, input+len, input, destbuf, destbuf+bufsize, dest_end);
|
||||
|
||||
// determine the length of the converted sequence
|
||||
std::size_t length = dest_end - destbuf;
|
||||
|
||||
// get rid of the buffer
|
||||
delete[] destbuf;
|
||||
|
||||
// return the result
|
||||
return length;
|
||||
}
|
||||
10
Task/String-length/C++/string-length-6.cpp
Normal file
10
Task/String-length/C++/string-length-6.cpp
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
#include <iostream>
|
||||
|
||||
int main()
|
||||
{
|
||||
// Tür (German for door) in UTF8
|
||||
std::cout << char_length("\x54\xc3\xbc\x72", "de_DE.utf8") << "\n"; // outputs 3
|
||||
|
||||
// Tür in ISO-8859-1
|
||||
std::cout << char_length("\x54\xfc\x72", "de_DE") << "\n"; // outputs 3
|
||||
}
|
||||
2
Task/String-length/C-sharp/string-length-1.cs
Normal file
2
Task/String-length/C-sharp/string-length-1.cs
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
string s = "Hello, world!";
|
||||
int characterLength = s.Length;
|
||||
4
Task/String-length/C-sharp/string-length-2.cs
Normal file
4
Task/String-length/C-sharp/string-length-2.cs
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
using System.Text;
|
||||
|
||||
string s = "Hello, world!";
|
||||
int byteLength = Encoding.Unicode.GetByteCount(s);
|
||||
1
Task/String-length/C-sharp/string-length-3.cs
Normal file
1
Task/String-length/C-sharp/string-length-3.cs
Normal file
|
|
@ -0,0 +1 @@
|
|||
int utf8ByteLength = Encoding.UTF8.GetByteCount(s);
|
||||
9
Task/String-length/C/string-length-1.c
Normal file
9
Task/String-length/C/string-length-1.c
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
#include <string.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
const char *string = "Hello, world!";
|
||||
size_t length = strlen(string);
|
||||
|
||||
return 0;
|
||||
}
|
||||
10
Task/String-length/C/string-length-2.c
Normal file
10
Task/String-length/C/string-length-2.c
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
int main(void)
|
||||
{
|
||||
const char *string = "Hello, world!";
|
||||
size_t length = 0;
|
||||
|
||||
const char *p = string;
|
||||
while (*p++ != '\0') length++;
|
||||
|
||||
return 0;
|
||||
}
|
||||
9
Task/String-length/C/string-length-3.c
Normal file
9
Task/String-length/C/string-length-3.c
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
#include <stdlib.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
char s[] = "Hello, world!";
|
||||
size_t length = sizeof s - 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
14
Task/String-length/C/string-length-4.c
Normal file
14
Task/String-length/C/string-length-4.c
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
#include <stdio.h>
|
||||
#include <wchar.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
wchar_t *s = L"\x304A\x306F\x3088\x3046"; /* Japanese hiragana ohayou */
|
||||
size_t length;
|
||||
|
||||
length = wcslen(s);
|
||||
printf("Length in characters = %d\n", length);
|
||||
printf("Length in bytes = %d\n", sizeof(s) * sizeof(wchar_t));
|
||||
|
||||
return 0;
|
||||
}
|
||||
13
Task/String-length/C/string-length-5.c
Normal file
13
Task/String-length/C/string-length-5.c
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <locale.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
setlocale(LC_CTYPE, "");
|
||||
char moose[] = "møøse";
|
||||
printf("bytes: %d\n", sizeof(moose) - 1);
|
||||
printf("chars: %d\n", (int)mbstowcs(0, moose, 0));
|
||||
|
||||
return 0;
|
||||
}
|
||||
1
Task/String-length/COBOL/string-length-1.cobol
Normal file
1
Task/String-length/COBOL/string-length-1.cobol
Normal file
|
|
@ -0,0 +1 @@
|
|||
FUNCTION BYTE-LENGTH(str)
|
||||
1
Task/String-length/COBOL/string-length-2.cobol
Normal file
1
Task/String-length/COBOL/string-length-2.cobol
Normal file
|
|
@ -0,0 +1 @@
|
|||
LENGTH OF str
|
||||
1
Task/String-length/COBOL/string-length-3.cobol
Normal file
1
Task/String-length/COBOL/string-length-3.cobol
Normal file
|
|
@ -0,0 +1 @@
|
|||
FUNCTION LENGTH-AN(str)
|
||||
1
Task/String-length/COBOL/string-length-4.cobol
Normal file
1
Task/String-length/COBOL/string-length-4.cobol
Normal file
|
|
@ -0,0 +1 @@
|
|||
FUNCTION LENGTH(str)
|
||||
6
Task/String-length/Clean/string-length.clean
Normal file
6
Task/String-length/Clean/string-length.clean
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
import StdEnv
|
||||
|
||||
strlen :: String -> Int
|
||||
strlen string = size string
|
||||
|
||||
Start = strlen "Hello, world!"
|
||||
8
Task/String-length/Clojure/string-length-1.clj
Normal file
8
Task/String-length/Clojure/string-length-1.clj
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
(def utf-8-octet-length #(-> % (.getBytes "UTF-8") count))
|
||||
(map utf-8-octet-length ["møøse" "𝔘𝔫𝔦𝔠𝔬𝔡𝔢" "J\u0332o\u0332s\u0332e\u0301\u0332"]) ; (7 28 14)
|
||||
|
||||
(def utf-16-octet-length (comp (partial * 2) count))
|
||||
(map utf-16-octet-length ["møøse" "𝔘𝔫𝔦𝔠𝔬𝔡𝔢" "J\u0332o\u0332s\u0332e\u0301\u0332"]) ; (10 28 18)
|
||||
|
||||
(def code-unit-length count)
|
||||
(map code-unit-length ["møøse" "𝔘𝔫𝔦𝔠𝔬𝔡𝔢" "J\u0332o\u0332s\u0332e\u0301\u0332"]) ; (5 14 9)
|
||||
2
Task/String-length/Clojure/string-length-2.clj
Normal file
2
Task/String-length/Clojure/string-length-2.clj
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
(def character-length #(.codePointCount % 0 (count %)))
|
||||
(map character-length ["møøse" "𝔘𝔫𝔦𝔠𝔬𝔡𝔢" "J\u0332o\u0332s\u0332e\u0301\u0332"]) ; (5 7 9)
|
||||
8
Task/String-length/Clojure/string-length-3.clj
Normal file
8
Task/String-length/Clojure/string-length-3.clj
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
(def grapheme-length
|
||||
#(->> (doto (java.text.BreakIterator/getCharacterInstance)
|
||||
(.setText %))
|
||||
(partial (memfn next))
|
||||
repeatedly
|
||||
(take-while (partial not= java.text.BreakIterator/DONE))
|
||||
count))
|
||||
(map grapheme-length ["møøse" "𝔘𝔫𝔦𝔠𝔬𝔡𝔢" "J\u0332o\u0332s\u0332e\u0301\u0332"]) ; (5 7 4)
|
||||
6
Task/String-length/ColdFusion/string-length-1.cfm
Normal file
6
Task/String-length/ColdFusion/string-length-1.cfm
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
<cfoutput>
|
||||
<cfset str = "Hello World">
|
||||
<cfset j = createObject("java","java.lang.String").init(str)>
|
||||
<cfset t = j.getBytes()>
|
||||
<p>#arrayLen(t)#</p>
|
||||
</cfoutput>
|
||||
1
Task/String-length/ColdFusion/string-length-2.cfm
Normal file
1
Task/String-length/ColdFusion/string-length-2.cfm
Normal file
|
|
@ -0,0 +1 @@
|
|||
#len("Hello World")#
|
||||
2
Task/String-length/Commodore-BASIC/string-length.basic
Normal file
2
Task/String-length/Commodore-BASIC/string-length.basic
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
10 INPUT A$
|
||||
20 PRINT LEN(A$)
|
||||
1
Task/String-length/Common-Lisp/string-length-1.lisp
Normal file
1
Task/String-length/Common-Lisp/string-length-1.lisp
Normal file
|
|
@ -0,0 +1 @@
|
|||
(length (sb-ext:string-to-octets "Hello Wørld"))
|
||||
1
Task/String-length/Common-Lisp/string-length-2.lisp
Normal file
1
Task/String-length/Common-Lisp/string-length-2.lisp
Normal file
|
|
@ -0,0 +1 @@
|
|||
(length "Hello World")
|
||||
14
Task/String-length/Component-Pascal/string-length-1.pas
Normal file
14
Task/String-length/Component-Pascal/string-length-1.pas
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
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.
|
||||
15
Task/String-length/Component-Pascal/string-length-2.pas
Normal file
15
Task/String-length/Component-Pascal/string-length-2.pas
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
MODULE TestLen;
|
||||
|
||||
IMPORT Out;
|
||||
|
||||
PROCEDURE DoByteLength*;
|
||||
VAR s: ARRAY 16 OF CHAR; len, v: INTEGER;
|
||||
BEGIN
|
||||
s := "møøse";
|
||||
len := LEN(s$);
|
||||
v := SIZE(CHAR) * len;
|
||||
Out.String("s: "); Out.String(s); Out.Ln;
|
||||
Out.String("Length of characters in bytes: "); Out.Int(v, 0); Out.Ln
|
||||
END DoByteLength;
|
||||
|
||||
END TestLen.
|
||||
1
Task/String-length/Crystal/string-length-1.crystal
Normal file
1
Task/String-length/Crystal/string-length-1.crystal
Normal file
|
|
@ -0,0 +1 @@
|
|||
"J̲o̲s̲é̲".bytesize
|
||||
1
Task/String-length/Crystal/string-length-2.crystal
Normal file
1
Task/String-length/Crystal/string-length-2.crystal
Normal file
|
|
@ -0,0 +1 @@
|
|||
"J̲o̲s̲é̲".chars.length
|
||||
31
Task/String-length/D/string-length-1.d
Normal file
31
Task/String-length/D/string-length-1.d
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
import std.stdio;
|
||||
|
||||
void showByteLen(T)(T[] str) {
|
||||
writefln("Byte length: %2d - %(%02x%)",
|
||||
str.length * T.sizeof, cast(ubyte[])str);
|
||||
}
|
||||
|
||||
void main() {
|
||||
string s1a = "møøse"; // UTF-8
|
||||
showByteLen(s1a);
|
||||
wstring s1b = "møøse"; // UTF-16
|
||||
showByteLen(s1b);
|
||||
dstring s1c = "møøse"; // UTF-32
|
||||
showByteLen(s1c);
|
||||
writeln();
|
||||
|
||||
string s2a = "𝔘𝔫𝔦𝔠𝔬𝔡𝔢";
|
||||
showByteLen(s2a);
|
||||
wstring s2b = "𝔘𝔫𝔦𝔠𝔬𝔡𝔢";
|
||||
showByteLen(s2b);
|
||||
dstring s2c = "𝔘𝔫𝔦𝔠𝔬𝔡𝔢";
|
||||
showByteLen(s2c);
|
||||
writeln();
|
||||
|
||||
string s3a = "J̲o̲s̲é̲";
|
||||
showByteLen(s3a);
|
||||
wstring s3b = "J̲o̲s̲é̲";
|
||||
showByteLen(s3b);
|
||||
dstring s3c = "J̲o̲s̲é̲";
|
||||
showByteLen(s3c);
|
||||
}
|
||||
31
Task/String-length/D/string-length-2.d
Normal file
31
Task/String-length/D/string-length-2.d
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
import std.stdio, std.range, std.conv;
|
||||
|
||||
void showCodePointsLen(T)(T[] str) {
|
||||
writefln("Character length: %2d - %(%x %)",
|
||||
str.walkLength(), cast(uint[])to!(dchar[])(str));
|
||||
}
|
||||
|
||||
void main() {
|
||||
string s1a = "møøse"; // UTF-8
|
||||
showCodePointsLen(s1a);
|
||||
wstring s1b = "møøse"; // UTF-16
|
||||
showCodePointsLen(s1b);
|
||||
dstring s1c = "møøse"; // UTF-32
|
||||
showCodePointsLen(s1c);
|
||||
writeln();
|
||||
|
||||
string s2a = "𝔘𝔫𝔦𝔠𝔬𝔡𝔢";
|
||||
showCodePointsLen(s2a);
|
||||
wstring s2b = "𝔘𝔫𝔦𝔠𝔬𝔡𝔢";
|
||||
showCodePointsLen(s2b);
|
||||
dstring s2c = "𝔘𝔫𝔦𝔠𝔬𝔡𝔢";
|
||||
showCodePointsLen(s2c);
|
||||
writeln();
|
||||
|
||||
string s3a = "J̲o̲s̲é̲";
|
||||
showCodePointsLen(s3a);
|
||||
wstring s3b = "J̲o̲s̲é̲";
|
||||
showCodePointsLen(s3b);
|
||||
dstring s3c = "J̲o̲s̲é̲";
|
||||
showCodePointsLen(s3c);
|
||||
}
|
||||
1
Task/String-length/DataWeave/string-length.dw
Normal file
1
Task/String-length/DataWeave/string-length.dw
Normal file
|
|
@ -0,0 +1 @@
|
|||
sizeOf("foo")
|
||||
3
Task/String-length/Dc/string-length-1.dc
Normal file
3
Task/String-length/Dc/string-length-1.dc
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
[256 / d 0<L 1 + ] sL
|
||||
22405534230753963835153736737 d P A P
|
||||
lL x f
|
||||
1
Task/String-length/Dc/string-length-2.dc
Normal file
1
Task/String-length/Dc/string-length-2.dc
Normal file
|
|
@ -0,0 +1 @@
|
|||
[abcde]Zp
|
||||
1
Task/String-length/Dyalect/string-length.dyalect
Normal file
1
Task/String-length/Dyalect/string-length.dyalect
Normal file
|
|
@ -0,0 +1 @@
|
|||
"Hello World".Length()
|
||||
1
Task/String-length/E/string-length.e
Normal file
1
Task/String-length/E/string-length.e
Normal file
|
|
@ -0,0 +1 @@
|
|||
"Hello World".size()
|
||||
4
Task/String-length/EMal/string-length-1.emal
Normal file
4
Task/String-length/EMal/string-length-1.emal
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
text moose = "møøse"
|
||||
text unicode = "𝔘𝔫𝔦𝔠𝔬𝔡𝔢"
|
||||
text jose = "J" + 0U0332 + "o" + 0U0332 + "s" + 0U0332 + "e" + 0U0301 + 0U0332
|
||||
text emoji = "𠇰😈🎶🔥é-"
|
||||
4
Task/String-length/EMal/string-length-2.emal
Normal file
4
Task/String-length/EMal/string-length-2.emal
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
writeLine((blob!moose).length)
|
||||
writeLine((blob!unicode).length)
|
||||
writeLine((blob!jose).length)
|
||||
writeLine((blob!emoji).length)
|
||||
4
Task/String-length/EMal/string-length-3.emal
Normal file
4
Task/String-length/EMal/string-length-3.emal
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
writeLine(moose.codePointsLength)
|
||||
writeLine(unicode.codePointsLength)
|
||||
writeLine(jose.codePointsLength)
|
||||
writeLine(emoji.codePointsLength)
|
||||
4
Task/String-length/EMal/string-length-4.emal
Normal file
4
Task/String-length/EMal/string-length-4.emal
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
writeLine(moose.graphemesLength)
|
||||
writeLine(unicode.graphemesLength)
|
||||
writeLine(jose.graphemesLength)
|
||||
writeLine(emoji.graphemesLength)
|
||||
8
Task/String-length/EasyLang/string-length.easy
Normal file
8
Task/String-length/EasyLang/string-length.easy
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
# 5
|
||||
print len "møøse"
|
||||
# 7
|
||||
print len "𝔘𝔫𝔦𝔠𝔬𝔡𝔢"
|
||||
# 8
|
||||
print len "J̲o̲s̲é̲"
|
||||
# 1
|
||||
print len "😀"
|
||||
11
Task/String-length/Elena/string-length-1.elena
Normal file
11
Task/String-length/Elena/string-length-1.elena
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
import extensions;
|
||||
|
||||
public 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
|
||||
}
|
||||
10
Task/String-length/Elena/string-length-2.elena
Normal file
10
Task/String-length/Elena/string-length-2.elena
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
import extensions;
|
||||
|
||||
public 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
|
||||
}
|
||||
3
Task/String-length/Elixir/string-length-1.elixir
Normal file
3
Task/String-length/Elixir/string-length-1.elixir
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
name = "J\x{332}o\x{332}s\x{332}e\x{301}\x{332}"
|
||||
byte_size(name)
|
||||
# => 14
|
||||
3
Task/String-length/Elixir/string-length-2.elixir
Normal file
3
Task/String-length/Elixir/string-length-2.elixir
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
name = "J\x{332}o\x{332}s\x{332}e\x{301}\x{332}"
|
||||
Enum.count(String.codepoints(name))
|
||||
# => 9
|
||||
3
Task/String-length/Elixir/string-length-3.elixir
Normal file
3
Task/String-length/Elixir/string-length-3.elixir
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
name = "J\x{332}o\x{332}s\x{332}e\x{301}\x{332}"
|
||||
String.length(name)
|
||||
# => 4
|
||||
2
Task/String-length/Emacs-Lisp/string-length-1.l
Normal file
2
Task/String-length/Emacs-Lisp/string-length-1.l
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
(length "hello")
|
||||
;; => 5
|
||||
2
Task/String-length/Emacs-Lisp/string-length-2.l
Normal file
2
Task/String-length/Emacs-Lisp/string-length-2.l
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
(string-bytes "\u1D518\u1D52B\u1D526")
|
||||
;; => 12
|
||||
7
Task/String-length/Emacs-Lisp/string-length-3.l
Normal file
7
Task/String-length/Emacs-Lisp/string-length-3.l
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
(let ((str (apply 'string
|
||||
(mapcar (lambda (c) (decode-char 'ucs c))
|
||||
'(#x1112 #x1161 #x11ab #x1100 #x1173 #x11af)))))
|
||||
(list (length str)
|
||||
(string-bytes str)
|
||||
(string-width str)))
|
||||
;; => (6 18 4) ;; in emacs 23 up
|
||||
1
Task/String-length/Euphoria/string-length.euphoria
Normal file
1
Task/String-length/Euphoria/string-length.euphoria
Normal file
|
|
@ -0,0 +1 @@
|
|||
print(1,length("Hello World"))
|
||||
2
Task/String-length/F-Sharp/string-length-1.fs
Normal file
2
Task/String-length/F-Sharp/string-length-1.fs
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
open System.Text
|
||||
let byte_length str = Encoding.UTF8.GetByteCount(str)
|
||||
1
Task/String-length/F-Sharp/string-length-2.fs
Normal file
1
Task/String-length/F-Sharp/string-length-2.fs
Normal file
|
|
@ -0,0 +1 @@
|
|||
"Hello, World".Length
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue