Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
5
Task/Empty-string/00-META.yaml
Normal file
5
Task/Empty-string/00-META.yaml
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
category:
|
||||
- String manipulation
|
||||
- Simple
|
||||
from: http://rosettacode.org/wiki/Empty_string
|
||||
13
Task/Empty-string/00-TASK.txt
Normal file
13
Task/Empty-string/00-TASK.txt
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
Languages may have features for dealing specifically with empty strings
|
||||
(those containing no characters).
|
||||
|
||||
|
||||
;Task:
|
||||
::* Demonstrate how to assign an empty string to a variable.
|
||||
::* Demonstrate how to check that a string is empty.
|
||||
::* Demonstrate how to check that a string is not empty.
|
||||
|
||||
|
||||
{{Template:Strings}}
|
||||
<br><br>
|
||||
|
||||
5
Task/Empty-string/11l/empty-string.11l
Normal file
5
Task/Empty-string/11l/empty-string.11l
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
V s = ‘’
|
||||
I s.empty
|
||||
print(‘String s is empty.’)
|
||||
I !s.empty
|
||||
print(‘String s is not empty.’)
|
||||
2
Task/Empty-string/6502-Assembly/empty-string-1.6502
Normal file
2
Task/Empty-string/6502-Assembly/empty-string-1.6502
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
EmptyString:
|
||||
byte 0
|
||||
16
Task/Empty-string/6502-Assembly/empty-string-2.6502
Normal file
16
Task/Empty-string/6502-Assembly/empty-string-2.6502
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
lda #<EmptyString ;address of string we wish to check
|
||||
sta $00
|
||||
lda #>EmptyString
|
||||
sta $01 ;the empty string has been assigned to zero page pair $00 and $01
|
||||
|
||||
ldy #0
|
||||
ldx #0
|
||||
getStringLength:
|
||||
lda ($00),y
|
||||
beq Terminated
|
||||
iny
|
||||
jmp getStringLength
|
||||
Terminated:
|
||||
cpy #0
|
||||
beq StringIsEmpty ;if this branch is taken, the string is empty
|
||||
;otherwise, the string is not empty
|
||||
3
Task/Empty-string/68000-Assembly/empty-string-1.68000
Normal file
3
Task/Empty-string/68000-Assembly/empty-string-1.68000
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
EmptyString:
|
||||
DC.B 0
|
||||
EVEN
|
||||
14
Task/Empty-string/68000-Assembly/empty-string-2.68000
Normal file
14
Task/Empty-string/68000-Assembly/empty-string-2.68000
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
LEA EmptyString,A0 ;assign the empty string to address register A0
|
||||
|
||||
getStringLength:
|
||||
MOVE.L A0,-(SP) ;push A0 onto the stack. This will be used to check if the string is empty.
|
||||
|
||||
loop_getStringLength:
|
||||
MOVE.B (A0)+,D0
|
||||
BEQ Terminated
|
||||
JMP loop_getStringLength
|
||||
|
||||
SUBQ.L #1,A0 ;after the terminator is read, A0 is incremented to point to the byte after it. This fixes that.
|
||||
CMP.L A0,(SP) ;compare the current A0 with the original value.
|
||||
BEQ StringIsEmpty ;if they are equal, then nothing was read besides the terminator. Therefore the string is empty.
|
||||
;if the above branch wasn't taken, the string is not empty and execution arrives here.
|
||||
1
Task/Empty-string/8th/empty-string-1.8th
Normal file
1
Task/Empty-string/8th/empty-string-1.8th
Normal file
|
|
@ -0,0 +1 @@
|
|||
"" var, str
|
||||
1
Task/Empty-string/8th/empty-string-2.8th
Normal file
1
Task/Empty-string/8th/empty-string-2.8th
Normal file
|
|
@ -0,0 +1 @@
|
|||
str @ s:len 0 n:= if ... then
|
||||
|
|
@ -0,0 +1 @@
|
|||
str: .asciz ""
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
mov x5, #0
|
||||
ldrb w5, [x0]
|
||||
cmp x5, #0
|
||||
56
Task/Empty-string/AArch64-Assembly/empty-string-3.aarch64
Normal file
56
Task/Empty-string/AArch64-Assembly/empty-string-3.aarch64
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
.equ STDOUT, 1
|
||||
.equ SVC_WRITE, 64
|
||||
.equ SVC_EXIT, 93
|
||||
|
||||
.text
|
||||
.global _start
|
||||
|
||||
_start:
|
||||
stp x29, x30, [sp, -16]!
|
||||
ldr x0, =str1
|
||||
mov x29, sp
|
||||
bl str_empty // str_empty("");
|
||||
ldr x0, =str2
|
||||
bl str_empty // str_empty("non-empty");
|
||||
ldp x29, x30, [sp], 16
|
||||
mov x0, #0
|
||||
b _exit
|
||||
|
||||
str1: .asciz ""
|
||||
str2: .asciz "non-empty"
|
||||
.align 4
|
||||
|
||||
// void str_empty(const char *s) - print "String is empty" if s is empty, "String is not empty" otherwise
|
||||
str_empty:
|
||||
mov x5, #0
|
||||
ldrb w5, [x0]
|
||||
ldr x1, =msg_empty
|
||||
ldr x3, =msg_not_empty
|
||||
mov x2, #16
|
||||
mov x4, #20
|
||||
cmp x5, #0
|
||||
csel x1, x1, x3, eq // msg = s[0] == 0 ? msg_empty : msg_not_empty;
|
||||
csel x2, x2, x4, eq // len = s[0] == 0 ? 16 : 20;
|
||||
mov x0, #STDOUT
|
||||
b _write // write(stdout, msg, len);
|
||||
|
||||
msg_empty:
|
||||
.ascii "String is empty\n"
|
||||
msg_not_empty:
|
||||
.ascii "String is not empty\n"
|
||||
.align 4
|
||||
|
||||
//////////////// system call wrappers
|
||||
// ssize_t _write(int fd, void *buf, size_t count)
|
||||
_write:
|
||||
stp x29, x30, [sp, -16]!
|
||||
mov x8, #SVC_WRITE
|
||||
mov x29, sp
|
||||
svc #0
|
||||
ldp x29, x30, [sp], 16
|
||||
ret
|
||||
|
||||
// void _exit(int retval)
|
||||
_exit:
|
||||
mov x8, #SVC_EXIT
|
||||
svc #0
|
||||
1
Task/Empty-string/ACL2/empty-string.acl2
Normal file
1
Task/Empty-string/ACL2/empty-string.acl2
Normal file
|
|
@ -0,0 +1 @@
|
|||
(= (length str) 0)
|
||||
12
Task/Empty-string/ALGOL-68/empty-string.alg
Normal file
12
Task/Empty-string/ALGOL-68/empty-string.alg
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
# declare a string variable and assign an empty string to it #
|
||||
STRING s := "";
|
||||
|
||||
# test the string is empty #
|
||||
IF s = "" THEN write( ( "s is empty", newline ) ) FI;
|
||||
|
||||
# test the string is not empty #
|
||||
IF s /= "" THEN write( ( "s is not empty", newline ) ) FI;
|
||||
|
||||
# as a string is an array of characters, we could also test for emptyness by #
|
||||
# checking for lower bound > upper bound #
|
||||
IF LWB s > UPB s THEN write( ( "s is still empty", newline ) ) FI
|
||||
6
Task/Empty-string/APL/empty-string.apl
Normal file
6
Task/Empty-string/APL/empty-string.apl
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
⍝⍝ Assign empty string to A
|
||||
A ← ''
|
||||
0 = ⍴∊ A
|
||||
1
|
||||
~0 = ⍴∊ A
|
||||
0
|
||||
83
Task/Empty-string/ARM-Assembly/empty-string.arm
Normal file
83
Task/Empty-string/ARM-Assembly/empty-string.arm
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
/* ARM assembly Raspberry PI */
|
||||
/* program strEmpty.s */
|
||||
|
||||
/* Constantes */
|
||||
.equ STDOUT, 1 @ Linux output console
|
||||
.equ EXIT, 1 @ Linux syscall
|
||||
.equ WRITE, 4 @ Linux syscall
|
||||
/* Initialized data */
|
||||
.data
|
||||
szNotEmptyString: .asciz "String is not empty. \n"
|
||||
szEmptyString: .asciz "String is empty. \n"
|
||||
@ empty string
|
||||
szString: .asciz "" @ with zero final
|
||||
szString1: .asciz "A" @ with zero final
|
||||
|
||||
/* UnInitialized data */
|
||||
.bss
|
||||
|
||||
/* code section */
|
||||
.text
|
||||
.global main
|
||||
main: /* entry of program */
|
||||
push {fp,lr} /* saves 2 registers */
|
||||
|
||||
@ load string
|
||||
ldr r1,iAdrszString
|
||||
ldrb r0,[r1] @ load first byte of string
|
||||
cmp r0,#0 @ compar with zero ?
|
||||
bne 1f
|
||||
ldr r0,iAdrszEmptyString
|
||||
bl affichageMess
|
||||
b 2f
|
||||
1:
|
||||
|
||||
ldr r0,iAdrszNotEmptyString
|
||||
bl affichageMess
|
||||
/* second string */
|
||||
2:
|
||||
@ load string 1
|
||||
ldr r1,iAdrszString1
|
||||
ldrb r0,[r1] @ load first byte of string
|
||||
cmp r0,#0 @ compar with zero ?
|
||||
bne 3f
|
||||
ldr r0,iAdrszEmptyString
|
||||
bl affichageMess
|
||||
b 100f
|
||||
3:
|
||||
ldr r0,iAdrszNotEmptyString
|
||||
bl affichageMess
|
||||
b 100f
|
||||
|
||||
100: /* standard end of the program */
|
||||
mov r0, #0 @ return code
|
||||
pop {fp,lr} @restaur 2 registers
|
||||
mov r7, #EXIT @ request to exit program
|
||||
swi 0 @ perform the system call
|
||||
iAdrszString: .int szString
|
||||
iAdrszString1: .int szString1
|
||||
iAdrszNotEmptyString: .int szNotEmptyString
|
||||
iAdrszEmptyString: .int szEmptyString
|
||||
|
||||
/******************************************************************/
|
||||
/* display text with size calculation */
|
||||
/******************************************************************/
|
||||
/* r0 contains the address of the message */
|
||||
affichageMess:
|
||||
push {fp,lr} /* save registres */
|
||||
push {r0,r1,r2,r7} /* save others registers */
|
||||
mov r2,#0 /* counter length */
|
||||
1: /* loop length calculation */
|
||||
ldrb r1,[r0,r2] /* read octet start position + index */
|
||||
cmp r1,#0 /* if 0 its over */
|
||||
addne r2,r2,#1 /* else add 1 in the length */
|
||||
bne 1b /* and loop */
|
||||
/* so here r2 contains the length of the message */
|
||||
mov r1,r0 /* address message in r1 */
|
||||
mov r0,#STDOUT /* code to write to the standard output Linux */
|
||||
mov r7, #WRITE /* code call system "write" */
|
||||
swi #0 /* call systeme */
|
||||
pop {r0,r1,r2,r7} /* restaur others registers */
|
||||
pop {fp,lr} /* restaur des 2 registres */
|
||||
bx lr /* return */
|
||||
|
||||
16
Task/Empty-string/AWK/empty-string.awk
Normal file
16
Task/Empty-string/AWK/empty-string.awk
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
#!/usr/bin/awk -f
|
||||
BEGIN {
|
||||
# Demonstrate how to assign an empty string to a variable.
|
||||
a="";
|
||||
b="XYZ";
|
||||
print "a = ",a;
|
||||
print "b = ",b;
|
||||
print "length(a)=",length(a);
|
||||
print "length(b)=",length(b);
|
||||
# Demonstrate how to check that a string is empty.
|
||||
print "Is a empty ?",length(a)==0;
|
||||
print "Is a not empty ?",length(a)!=0;
|
||||
# Demonstrate how to check that a string is not empty.
|
||||
print "Is b empty ?",length(b)==0;
|
||||
print "Is b not empty ?",length(b)!=0;
|
||||
}
|
||||
18
Task/Empty-string/Action-/empty-string.action
Normal file
18
Task/Empty-string/Action-/empty-string.action
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
PROC CheckIsEmpty(CHAR ARRAY s)
|
||||
PrintF("'%S' is empty? ",s)
|
||||
IF s(0)=0 THEN
|
||||
PrintE("True")
|
||||
ELSE
|
||||
PrintE("False")
|
||||
FI
|
||||
RETURN
|
||||
|
||||
PROC Main()
|
||||
CHAR ARRAY str1,str2
|
||||
|
||||
str1=""
|
||||
str2="text"
|
||||
|
||||
CheckIsEmpty(str1)
|
||||
CheckIsEmpty(str2)
|
||||
RETURN
|
||||
15
Task/Empty-string/Ada/empty-string.ada
Normal file
15
Task/Empty-string/Ada/empty-string.ada
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
procedure Empty_String is
|
||||
|
||||
function Is_Empty(S: String) return Boolean is
|
||||
begin
|
||||
return S = ""; -- test that S is empty
|
||||
end Is_Empty;
|
||||
|
||||
Empty: String := ""; -- Assign empty string
|
||||
XXXXX: String := "Not Empty";
|
||||
|
||||
begin
|
||||
if (not Is_Empty(Empty)) or Is_Empty(XXXXX) then
|
||||
raise Program_Error with "something went wrong very very badly!!!";
|
||||
end if;
|
||||
end Empty_String;
|
||||
8
Task/Empty-string/Aime/empty-string.aime
Normal file
8
Task/Empty-string/Aime/empty-string.aime
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
text s;
|
||||
s = "";
|
||||
if (length(s) == 0) {
|
||||
...
|
||||
}
|
||||
if (length(s) != 0) {
|
||||
....
|
||||
}
|
||||
2
Task/Empty-string/Apex/empty-string.apex
Normal file
2
Task/Empty-string/Apex/empty-string.apex
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
String.isBlank(record.txt_Field__c);
|
||||
--Returns true if the specified String is white space, empty (''), or null; otherwise, returns false.
|
||||
30
Task/Empty-string/AppleScript/empty-string.applescript
Normal file
30
Task/Empty-string/AppleScript/empty-string.applescript
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
-- assign empty string to str
|
||||
set str to ""
|
||||
|
||||
|
||||
-- check if string is empty
|
||||
if str is "" then
|
||||
-- str is empty
|
||||
end if
|
||||
-- or
|
||||
if id of str is {} then
|
||||
-- str is empty
|
||||
end if
|
||||
-- or
|
||||
if (count of str) is 0 then
|
||||
-- str is empty
|
||||
end if
|
||||
|
||||
|
||||
-- check if string is not empty
|
||||
if str is not "" then
|
||||
-- string is not empty
|
||||
end if
|
||||
-- or
|
||||
if id of str is not {} then
|
||||
-- str is not empty
|
||||
end if
|
||||
-- or
|
||||
if (count of str) is not 0 then
|
||||
-- str is not empty
|
||||
end if
|
||||
3
Task/Empty-string/Applesoft-BASIC/empty-string.basic
Normal file
3
Task/Empty-string/Applesoft-BASIC/empty-string.basic
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
10 LET A$ = "
|
||||
40 IF LEN (A$) = 0 THEN PRINT "THE STRING IS EMPTY"
|
||||
50 IF LEN (A$) THEN PRINT "THE STRING IS NOT EMPTY"
|
||||
9
Task/Empty-string/Arturo/empty-string.arturo
Normal file
9
Task/Empty-string/Arturo/empty-string.arturo
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
s: ""
|
||||
|
||||
if empty? s -> print "the string is empty"
|
||||
if 0 = size s -> print "yes, the string is empty"
|
||||
|
||||
s: "hello world"
|
||||
|
||||
if not? empty? s -> print "the string is not empty"
|
||||
if 0 < size s -> print "no, the string is not empty"
|
||||
21
Task/Empty-string/Asymptote/empty-string.asymptote
Normal file
21
Task/Empty-string/Asymptote/empty-string.asymptote
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
string c; //implicitly assigned an empty string
|
||||
if (length(c) == 0) {
|
||||
write("Empty string");
|
||||
} else {
|
||||
write("Non empty string");
|
||||
}
|
||||
|
||||
string s = ""; //explicitly assigned an empty string
|
||||
if (s == "") {
|
||||
write("Empty string");
|
||||
}
|
||||
if (s != "") {
|
||||
write("Non empty string");
|
||||
}
|
||||
|
||||
string t = "not empty";
|
||||
if (t != "") {
|
||||
write("Non empty string");
|
||||
} else {
|
||||
write("Empty string");
|
||||
}
|
||||
20
Task/Empty-string/AutoHotkey/empty-string.ahk
Normal file
20
Task/Empty-string/AutoHotkey/empty-string.ahk
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
;; Traditional
|
||||
; Assign an empty string:
|
||||
var =
|
||||
; Check that a string is empty:
|
||||
If var =
|
||||
MsgBox the var is empty
|
||||
; Check that a string is not empty
|
||||
If var !=
|
||||
Msgbox the var is not empty
|
||||
|
||||
|
||||
;; Expression mode:
|
||||
; Assign an empty string:
|
||||
var := ""
|
||||
; Check that a string is empty:
|
||||
If (var = "")
|
||||
MsgBox the var is empty
|
||||
; Check that a string is not empty
|
||||
If (var != "")
|
||||
Msgbox the var is not empty
|
||||
5
Task/Empty-string/Avail/empty-string-1.avail
Normal file
5
Task/Empty-string/Avail/empty-string-1.avail
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
emptyStringVar : string := "";
|
||||
Assert: emptyStringVar = "";
|
||||
Assert: emptyStringVar = <>;
|
||||
Assert: emptyStringVar is empty;
|
||||
Assert: |emptyStringVar| = 0;
|
||||
5
Task/Empty-string/Avail/empty-string-2.avail
Normal file
5
Task/Empty-string/Avail/empty-string-2.avail
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
nonemptyStringVar : string := "content!";
|
||||
Assert: nonemptyStringVar ≠ "";
|
||||
Assert: nonemptyStringVar ≠ <>;
|
||||
Assert: ¬nonemptyStringVar is empty;
|
||||
Assert: |nonemptyStringVar| > 0;
|
||||
1
Task/Empty-string/Avail/empty-string-3.avail
Normal file
1
Task/Empty-string/Avail/empty-string-3.avail
Normal file
|
|
@ -0,0 +1 @@
|
|||
Assert: nonemptyStringVar ∈ nonempty string;
|
||||
6
Task/Empty-string/Axe/empty-string.axe
Normal file
6
Task/Empty-string/Axe/empty-string.axe
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
""→Str1
|
||||
!If length(Str1)
|
||||
Disp "EMPTY",i
|
||||
Else
|
||||
Disp "NOT EMPTY",i
|
||||
End
|
||||
4
Task/Empty-string/BASIC/empty-string.basic
Normal file
4
Task/Empty-string/BASIC/empty-string.basic
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
10 LET A$=""
|
||||
20 IF A$="" THEN PRINT "THE STRING IS EMPTY"
|
||||
30 IF A$<>"" THEN PRINT "THE STRING IS NOT EMPTY"
|
||||
40 END
|
||||
15
Task/Empty-string/BASIC256/empty-string.basic
Normal file
15
Task/Empty-string/BASIC256/empty-string.basic
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
subroutine IsEmpty (s$)
|
||||
if length(s$) = 0 then
|
||||
print "String is empty"
|
||||
else
|
||||
print "String is not empty"
|
||||
end if
|
||||
if s$ = "" then print "yes, the string is empty"
|
||||
if s$ <> "" then print "no, the string is not empty"
|
||||
end subroutine
|
||||
|
||||
t$ = ""
|
||||
call IsEmpty (t$)
|
||||
u$ = "not empty"
|
||||
call IsEmpty (u$)
|
||||
end
|
||||
8
Task/Empty-string/BBC-BASIC/empty-string.basic
Normal file
8
Task/Empty-string/BBC-BASIC/empty-string.basic
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
REM assign an empty string to a variable:
|
||||
var$ = ""
|
||||
|
||||
REM Check that a string is empty:
|
||||
IF var$ = "" THEN PRINT "String is empty"
|
||||
|
||||
REM Check that a string is not empty:
|
||||
IF var$ <> "" THEN PRINT "String is not empty"
|
||||
4
Task/Empty-string/BQN/empty-string-1.bqn
Normal file
4
Task/Empty-string/BQN/empty-string-1.bqn
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
•Show ""
|
||||
•Show 0 = ≠ ""
|
||||
•Show 0 ≠ ≠ ""
|
||||
•Show "" ≡ ⟨⟩
|
||||
4
Task/Empty-string/BQN/empty-string-2.bqn
Normal file
4
Task/Empty-string/BQN/empty-string-2.bqn
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
⟨⟩
|
||||
1
|
||||
0
|
||||
1
|
||||
4
Task/Empty-string/BaCon/empty-string.bacon
Normal file
4
Task/Empty-string/BaCon/empty-string.bacon
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
' Empty string
|
||||
a$ = ""
|
||||
IF a$ = "" THEN PRINT "Empty string"
|
||||
IF a$ != "" THEN PRINT "Non empty string"
|
||||
14
Task/Empty-string/Batch-File/empty-string.bat
Normal file
14
Task/Empty-string/Batch-File/empty-string.bat
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
@echo off
|
||||
|
||||
::set "var" as a blank string.
|
||||
set var=
|
||||
|
||||
::check if "var" is a blank string.
|
||||
if not defined var echo Var is a blank string.
|
||||
::Alternatively,
|
||||
if %var%@ equ @ echo Var is a blank string.
|
||||
|
||||
::check if "var" is not a blank string.
|
||||
if defined var echo Var is defined.
|
||||
::Alternatively,
|
||||
if %var%@ neq @ echo Var is not a blank string.
|
||||
20
Task/Empty-string/Beef/empty-string.beef
Normal file
20
Task/Empty-string/Beef/empty-string.beef
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
using System;
|
||||
|
||||
namespace EmptyString
|
||||
{
|
||||
class Program
|
||||
{
|
||||
public static void Main()
|
||||
{
|
||||
String s = scope .();
|
||||
if (s.IsEmpty)
|
||||
{
|
||||
Console.Writeln("string empty");
|
||||
}
|
||||
if (!s.IsEmpty)
|
||||
{
|
||||
Console.Writeln("string not empty");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
9
Task/Empty-string/Bracmat/empty-string.bracmat
Normal file
9
Task/Empty-string/Bracmat/empty-string.bracmat
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
( :?a
|
||||
& (b=)
|
||||
& abra:?c
|
||||
& (d=cadabra)
|
||||
& !a: { a is empty string }
|
||||
& !b: { b is also empty string }
|
||||
& !c:~ { c is not an empty string }
|
||||
& !d:~ { neither is d an empty string }
|
||||
)
|
||||
6
Task/Empty-string/Burlesque/empty-string.blq
Normal file
6
Task/Empty-string/Burlesque/empty-string.blq
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
blsq ) ""
|
||||
""
|
||||
blsq ) ""nu
|
||||
1
|
||||
blsq ) "a"nu
|
||||
0
|
||||
38
Task/Empty-string/C++/empty-string.cpp
Normal file
38
Task/Empty-string/C++/empty-string.cpp
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
#include <string>
|
||||
|
||||
// ...
|
||||
|
||||
|
||||
// empty string declaration
|
||||
std::string str; // (default constructed)
|
||||
std::string str(); // (default constructor, no parameters)
|
||||
std::string str{}; // (default initialized)
|
||||
std::string str(""); // (const char[] conversion)
|
||||
std::string str{""}; // (const char[] initializer list)
|
||||
|
||||
|
||||
|
||||
if (str.empty()) { ... } // to test if string is empty
|
||||
|
||||
// we could also use the following
|
||||
if (str.length() == 0) { ... }
|
||||
if (str == "") { ... }
|
||||
|
||||
// make a std::string empty
|
||||
str.clear(); // (builtin clear function)
|
||||
str = ""; // replace contents with empty string
|
||||
str = {}; // swap contents with temp string (empty),then destruct temp
|
||||
|
||||
// swap with empty string
|
||||
std::string tmp{}; // temp empty string
|
||||
str.swap(tmp); // (builtin swap function)
|
||||
std::swap(str, tmp); // swap contents with tmp
|
||||
|
||||
|
||||
// create an array of empty strings
|
||||
std::string s_array[100]; // 100 initialized to "" (fixed size)
|
||||
std::array<std::string, 100> arr; // 100 initialized to "" (fixed size)
|
||||
std::vector<std::string>(100,""); // 100 initialized to "" (variable size, 100 starting size)
|
||||
|
||||
// create empty string as default parameter
|
||||
void func( std::string& s = {} ); // {} generated default std:string instance
|
||||
9
Task/Empty-string/C-sharp/empty-string-1.cs
Normal file
9
Task/Empty-string/C-sharp/empty-string-1.cs
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
using System;
|
||||
|
||||
class Program {
|
||||
static void Main (string[] args) {
|
||||
string example = string.Empty;
|
||||
if (string.IsNullOrEmpty(example)) { }
|
||||
if (!string.IsNullOrEmpty(example)) { }
|
||||
}
|
||||
}
|
||||
113
Task/Empty-string/C-sharp/empty-string-2.cs
Normal file
113
Task/Empty-string/C-sharp/empty-string-2.cs
Normal file
|
|
@ -0,0 +1,113 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
static class Program
|
||||
{
|
||||
// In short:
|
||||
public static void Foo()
|
||||
{
|
||||
string s;
|
||||
|
||||
// Assign empty string:
|
||||
s = "";
|
||||
// or
|
||||
s = string.Empty;
|
||||
|
||||
// Check for empty string only (false if s is null):
|
||||
if (s != null && s.Length == 0) { }
|
||||
|
||||
// Check for null or empty (more idiomatic in .NET):
|
||||
if (string.IsNullOrEmpty(s)) { }
|
||||
}
|
||||
|
||||
public static void Main()
|
||||
{
|
||||
// Equality is somewhat convoluted in .NET.
|
||||
// The methods above are the author's recommendation for each case.
|
||||
|
||||
// s is initialized to null. It is a variable of the System.String type that is a null reference and is not
|
||||
// the empty string.
|
||||
string s = null;
|
||||
|
||||
// Alias Console.WriteLine(bool) with a shorter name to make the demonstration code less verbose.
|
||||
Action<bool> P = Console.WriteLine;
|
||||
|
||||
// Assign the empty string literal to s.
|
||||
s = "";
|
||||
|
||||
// ' Assign String.Empty to s.
|
||||
s = string.Empty;
|
||||
|
||||
// The empty string literal is the same object reference as String.Empty because of string interning, meaning the
|
||||
// behavior of the two is identical.
|
||||
// From this point on, "" will be used instead of String.Empty for brevity.
|
||||
|
||||
//#== operator (object)
|
||||
// The == operator tests for reference equality when overload resolution fails to find an operator defined by
|
||||
// either operand type. However, which strings are interned is a CLR implementation detail and may be unreliable
|
||||
// when comparing non-empty strings. The equivalent in VB.NET would be s Is "".
|
||||
// Note that there is no such operator as Object.op_Equality(Object, Object): the use of the == operator for
|
||||
// types of type Object is a C# language feature.
|
||||
P((object)s == "");
|
||||
|
||||
//#Object.ReferenceEquals(Object, Object)
|
||||
// The previous line is semantically to the following, though it does not involve a method call.
|
||||
P(object.ReferenceEquals(s, ""));
|
||||
|
||||
//#String.op_Equality(String, String)
|
||||
// The equality operator of System.String is implemented as a call to String.Equals(String). Operators cannot be
|
||||
// called with method syntax in C#.
|
||||
P(s == "");
|
||||
|
||||
//#String.Equals(String, String)
|
||||
// Call the static method defined on the String type, which first calls Object.ReferenceEquals and then, after
|
||||
// verifying that both are strings of the same length, compares the strings character-by-character.
|
||||
P(string.Equals(s, ""));
|
||||
|
||||
//#Object.Equals(Object, Object)
|
||||
// First checks for reference equality and whether one or both of the arguments is null. It then invokes the
|
||||
// instance Equals method of the left parameter.
|
||||
P(object.Equals(s, ""));
|
||||
|
||||
//#String.Equals(String)
|
||||
// The method is called with the string literal as the receiver because a NullReferenceException is thrown if s
|
||||
// is null.
|
||||
P("".Equals(s));
|
||||
|
||||
//#String.Length
|
||||
// Check the Length property. The ?. (null-conditional) operator is used to avoid NullReferenceException. The Equals
|
||||
// call above can also be done this way. Null propagation makes the equality operator return false if one operand
|
||||
// is a Nullable<T> and does not have a value, making this result in false when s is null.
|
||||
P(s?.Length == 0);
|
||||
|
||||
//#String.Length
|
||||
// A more traditional version of the null-conditional using a guard clause.
|
||||
// Both the null-conditional and this are noticeably (~4 times) faster than "".Equals(s). In general, it appears that
|
||||
// for empty strings, using the length is faster than using an equality comparison.
|
||||
P(s != null && s.Length == 0);
|
||||
|
||||
//#String.IsNullOrEmpty(String)
|
||||
// Note that all of the other methods give false for null.
|
||||
// A static method of System.String that returns true if the string is null or its length is zero.
|
||||
P(string.IsNullOrEmpty(s));
|
||||
|
||||
//#System.Collections.Generic.EqualityComparer(Of String).Default.Equals(String, String)
|
||||
// The EqualityComparer(Of T) class provides default implementations when an IEqualityComparer(Of T) is required.
|
||||
// The implementation for String calls String.Equals(String).
|
||||
P(EqualityComparer<string>.Default.Equals(s, ""));
|
||||
|
||||
Console.WriteLine();
|
||||
|
||||
// Each of the means described above, except testing for a non-empty string.
|
||||
P((object)s != "");
|
||||
P(!object.ReferenceEquals(s, ""));
|
||||
P(s != "");
|
||||
P(!string.Equals(s, ""));
|
||||
P(!object.Equals(s, ""));
|
||||
P(!"".Equals(s));
|
||||
P(s?.Length != 0); // Still false when s is null!
|
||||
P(s == null || s.Length != 0);
|
||||
P(!string.IsNullOrEmpty(s));
|
||||
P(!EqualityComparer<string>.Default.Equals(s, ""));
|
||||
}
|
||||
}
|
||||
19
Task/Empty-string/C/empty-string.c
Normal file
19
Task/Empty-string/C/empty-string.c
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
#include <string.h>
|
||||
|
||||
/* ... */
|
||||
|
||||
/* assign an empty string */
|
||||
const char *str = "";
|
||||
|
||||
/* to test a null string */
|
||||
if (str) { ... }
|
||||
|
||||
/* to test if string is empty */
|
||||
if (str[0] == '\0') { ... }
|
||||
|
||||
/* or equivalently use strlen function
|
||||
strlen will seg fault on NULL pointer, so check first */
|
||||
if ( (str == NULL) || (strlen(str) == 0)) { ... }
|
||||
|
||||
/* or compare to a known empty string, same thing. "== 0" means strings are equal */
|
||||
if (strcmp(str, "") == 0) { ... }
|
||||
23
Task/Empty-string/COBOL/empty-string.cobol
Normal file
23
Task/Empty-string/COBOL/empty-string.cobol
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
IDENTIFICATION DIVISION.
|
||||
PROGRAM-ID. EMPTYSTR.
|
||||
|
||||
DATA DIVISION.
|
||||
WORKING-STORAGE SECTION.
|
||||
01 str PIC X(10).
|
||||
|
||||
PROCEDURE DIVISION.
|
||||
Begin.
|
||||
|
||||
* * Assign an empty string.
|
||||
INITIALIZE str.
|
||||
|
||||
* * Or
|
||||
MOVE " " TO str.
|
||||
|
||||
IF (str = " ")
|
||||
DISPLAY "String is empty"
|
||||
ELSE
|
||||
DISPLAY "String is not empty"
|
||||
END-IF.
|
||||
|
||||
STOP RUN.
|
||||
15
Task/Empty-string/Chipmunk-Basic/empty-string.basic
Normal file
15
Task/Empty-string/Chipmunk-Basic/empty-string.basic
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
100 cls
|
||||
110 t$ = ""
|
||||
120 isempty(t$)
|
||||
130 u$ = "not empty"
|
||||
140 isempty(u$)
|
||||
150 end
|
||||
160 sub isempty(s$)
|
||||
170 if len(s$) = 0 then
|
||||
180 print "String is empty"
|
||||
190 else
|
||||
200 print "String is not empty"
|
||||
210 endif
|
||||
220 if s$ = "" then print "yes, the string is empty"
|
||||
230 if s$ <> "" then print "no, the string is not empty"
|
||||
240 end sub
|
||||
6
Task/Empty-string/Clojure/empty-string.clj
Normal file
6
Task/Empty-string/Clojure/empty-string.clj
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
(def x "") ;x is "globally" declared to be the empty string
|
||||
(let [x ""]
|
||||
;x is bound to the empty string within the let
|
||||
)
|
||||
(= x "") ;true if x is the empty string
|
||||
(not= x "") ;true if x is not the empty string
|
||||
12
Task/Empty-string/CoffeeScript/empty-string.coffee
Normal file
12
Task/Empty-string/CoffeeScript/empty-string.coffee
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
isEmptyString = (s) ->
|
||||
# Returns true iff s is an empty string.
|
||||
# (This returns false for non-strings as well.)
|
||||
return true if s instanceof String and s.length == 0
|
||||
s == ''
|
||||
|
||||
empties = ["", '', new String()]
|
||||
non_empties = [new String('yo'), 'foo', {}]
|
||||
console.log (isEmptyString(v) for v in empties) # [true, true, true]
|
||||
console.log (isEmptyString(v) for v in non_empties) # [false, false, false]
|
||||
console.log (s = '') == "" # true
|
||||
console.log new String() == '' # false, due to underlying JavaScript's distinction between objects and primitives
|
||||
9
Task/Empty-string/Common-Lisp/empty-string.lisp
Normal file
9
Task/Empty-string/Common-Lisp/empty-string.lisp
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
(defparameter *s* "") ;; Binds dynamic variable *S* to the empty string ""
|
||||
(let ((s "")) ;; Binds the lexical variable S to the empty string ""
|
||||
(= (length s) 0) ;; Check if the string is empty
|
||||
(> (length s) 0) ;; Check if length of string is over 0 (that is: non-empty)
|
||||
|
||||
;; (length s) returns zero for any empty sequence. You're better off using type checking:
|
||||
(typep s '(string 0)) ;; only returns true on empty string
|
||||
(typep s '(and string
|
||||
(not (string 0))))) ;; only returns true on string that is not empty
|
||||
19
Task/Empty-string/Component-Pascal/empty-string.pas
Normal file
19
Task/Empty-string/Component-Pascal/empty-string.pas
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
MODULE EmptyString;
|
||||
IMPORT StdLog;
|
||||
|
||||
PROCEDURE Do*;
|
||||
VAR
|
||||
s: ARRAY 64 OF CHAR;
|
||||
(* s := "" <=> s[0] := 0X => s isEmpty*)
|
||||
BEGIN
|
||||
s := "";
|
||||
StdLog.String("Is 's' empty?:> ");StdLog.Bool(s = "");StdLog.Ln;
|
||||
StdLog.String("Is not 's' empty?:> ");StdLog.Bool(s # "");StdLog.Ln;
|
||||
StdLog.Ln;
|
||||
(* Or *)
|
||||
s := 0X;
|
||||
StdLog.String("Is 's' empty?:> ");StdLog.Bool(s = 0X);StdLog.Ln;
|
||||
StdLog.String("Is not 's' empty?:> ");StdLog.Bool(s # 0X);StdLog.Ln;
|
||||
StdLog.Ln;
|
||||
END Do;
|
||||
END EmptyString.
|
||||
27
Task/Empty-string/D/empty-string.d
Normal file
27
Task/Empty-string/D/empty-string.d
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
import std.array;
|
||||
|
||||
bool isEmptyNotNull(in string s) pure nothrow @safe {
|
||||
return s is "";
|
||||
}
|
||||
|
||||
void main(){
|
||||
string s1 = null;
|
||||
string s2 = "";
|
||||
|
||||
// the content is the same
|
||||
assert(!s1.length);
|
||||
assert(!s2.length);
|
||||
assert(s1 == "" && s1 == null);
|
||||
assert(s2 == "" && s2 == null);
|
||||
assert(s1 == s2);
|
||||
|
||||
// but they don't point to the same memory region
|
||||
assert(s1 is null && s1 !is "");
|
||||
assert(s2 is "" && s2 !is null);
|
||||
assert(s1 !is s2);
|
||||
assert(s1.ptr == null);
|
||||
assert(*s2.ptr == '\0'); // D string literals are \0 terminated
|
||||
|
||||
assert(s1.empty);
|
||||
assert(s2.isEmptyNotNull());
|
||||
}
|
||||
11
Task/Empty-string/DWScript/empty-string.dw
Normal file
11
Task/Empty-string/DWScript/empty-string.dw
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
var s : String;
|
||||
|
||||
s := ''; // assign an empty string (can also use "")
|
||||
|
||||
if s = '' then
|
||||
PrintLn('empty');
|
||||
|
||||
s := 'hello';
|
||||
|
||||
if s <> '' then
|
||||
PrintLn('not empty');
|
||||
11
Task/Empty-string/Dart/empty-string.dart
Normal file
11
Task/Empty-string/Dart/empty-string.dart
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
main() {
|
||||
var empty = '';
|
||||
|
||||
if (empty.isEmpty) {
|
||||
print('it is empty');
|
||||
}
|
||||
|
||||
if (empty.isNotEmpty) {
|
||||
print('it is not empty');
|
||||
}
|
||||
}
|
||||
20
Task/Empty-string/Delphi/empty-string.delphi
Normal file
20
Task/Empty-string/Delphi/empty-string.delphi
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
program EmptyString;
|
||||
|
||||
{$APPTYPE CONSOLE}
|
||||
|
||||
uses SysUtils;
|
||||
|
||||
function StringIsEmpty(const aString: string): Boolean;
|
||||
begin
|
||||
Result := aString = '';
|
||||
end;
|
||||
|
||||
var
|
||||
s: string;
|
||||
begin
|
||||
s := '';
|
||||
Writeln(StringIsEmpty(s)); // True
|
||||
|
||||
s := 'abc';
|
||||
Writeln(StringIsEmpty(s)); // False
|
||||
end.
|
||||
2
Task/Empty-string/Diego/empty-string-1.diego
Normal file
2
Task/Empty-string/Diego/empty-string-1.diego
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
add_str(s,⟦⟧); // empty string
|
||||
add_str(n); // null string (␀)
|
||||
17
Task/Empty-string/Diego/empty-string-2.diego
Normal file
17
Task/Empty-string/Diego/empty-string-2.diego
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
add_str(es,⟦⟧);
|
||||
add_bool(isEmpty)
|
||||
()_check⟦[es]==⟦⟧⟧;
|
||||
()_if⟦[es]≍⟦⟧⟧;
|
||||
()_calc({bool},⟦[es]==⟦⟧⟧);
|
||||
()_test⟦[lens]≍0⟧_lento(lens,⟦[es]⟧);
|
||||
()_is⟦[lens]>0⟧_lento(lens,⟦[es]⟧);
|
||||
()_check⟦[es]===({str},⟦⟧)⟧;
|
||||
()_if⟦[es]≡({str},⟦⟧)⟧;
|
||||
()_calc⟦≣[es]⟧_forme()_forall();
|
||||
()_not⟦[es]≠⟦⟧⟧;
|
||||
()_not()_bool[es];
|
||||
()_empty[es];
|
||||
(es)_equal⟦⟦⟧⟧;
|
||||
;
|
||||
log_console()_(isEmpty);
|
||||
log_console()_is(es); // is not null
|
||||
16
Task/Empty-string/Diego/empty-string-3.diego
Normal file
16
Task/Empty-string/Diego/empty-string-3.diego
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
add_str(s,⟦text⟧);
|
||||
add_bool(isNotEmpty)
|
||||
()_check⟦[s]!=⟦⟧⟧;
|
||||
()_if⟦[s]≭⟦⟧⟧;
|
||||
()_calc({bool},⟦[s]≠⟦⟧⟧);
|
||||
()_test⟦[lens]≠0⟧_lento(lens,⟦[s]⟧);
|
||||
()_is⟦[lens]<0⟧_lento(lens,⟦[s]⟧);
|
||||
()_check⟦[s]!==({str},⟦⟧)⟧;
|
||||
()_if⟦[s]≢({str},⟦⟧)⟧;
|
||||
()_calc⟦!≣[s]⟧_forme()_forany();
|
||||
()_bool[s];
|
||||
()_not()_empty[s];
|
||||
(s)_notequal⟦⟦⟧⟧;
|
||||
;
|
||||
log_console()_(isNotEmpty);
|
||||
log_console()_is(s); // is not null
|
||||
12
Task/Empty-string/Diego/empty-string-4.diego
Normal file
12
Task/Empty-string/Diego/empty-string-4.diego
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
add_str(n);
|
||||
add_bool(isNull)
|
||||
()_check⟦![n]⟧;
|
||||
()_calc({bool},⟦¬[n]⟧);
|
||||
()_isnull[n];
|
||||
()_not[n];
|
||||
()_isnull()_bool[n];
|
||||
()_none[n];
|
||||
()_any[n]_forme();
|
||||
(n)_equal⟦␀⟧;
|
||||
;
|
||||
log_console()_(isNull);
|
||||
1
Task/Empty-string/Dyalect/empty-string-1.dyalect
Normal file
1
Task/Empty-string/Dyalect/empty-string-1.dyalect
Normal file
|
|
@ -0,0 +1 @@
|
|||
var str = ""
|
||||
1
Task/Empty-string/Dyalect/empty-string-2.dyalect
Normal file
1
Task/Empty-string/Dyalect/empty-string-2.dyalect
Normal file
|
|
@ -0,0 +1 @@
|
|||
if str.IsEmpty() { }
|
||||
1
Task/Empty-string/Dyalect/empty-string-3.dyalect
Normal file
1
Task/Empty-string/Dyalect/empty-string-3.dyalect
Normal file
|
|
@ -0,0 +1 @@
|
|||
if !str.IsEmpty() { }
|
||||
7
Task/Empty-string/EasyLang/empty-string.easy
Normal file
7
Task/Empty-string/EasyLang/empty-string.easy
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
a$ = ""
|
||||
if a$ = ""
|
||||
print "empty"
|
||||
.
|
||||
if a$ <> ""
|
||||
print "no empty"
|
||||
.
|
||||
12
Task/Empty-string/Elena/empty-string.elena
Normal file
12
Task/Empty-string/Elena/empty-string.elena
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
import extensions;
|
||||
|
||||
public program()
|
||||
{
|
||||
auto s := emptyString;
|
||||
|
||||
if (s.isEmpty())
|
||||
{ console.printLine("'", s, "' is empty") };
|
||||
|
||||
if (s.isNonempty())
|
||||
{ console.printLine("'", s, "' is not empty") }
|
||||
}
|
||||
16
Task/Empty-string/Elixir/empty-string.elixir
Normal file
16
Task/Empty-string/Elixir/empty-string.elixir
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
empty_string = ""
|
||||
not_empty_string = "a"
|
||||
|
||||
empty_string == ""
|
||||
# => true
|
||||
String.length(empty_string) == 0
|
||||
# => true
|
||||
byte_size(empty_string) == 0
|
||||
# => true
|
||||
|
||||
not_empty_string == ""
|
||||
# => false
|
||||
String.length(not_empty_string) == 0
|
||||
# => false
|
||||
byte_size(not_empty_string) == 0
|
||||
# => false
|
||||
6
Task/Empty-string/Emacs-Lisp/empty-string.l
Normal file
6
Task/Empty-string/Emacs-Lisp/empty-string.l
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
(setq str "") ;; empty string literal
|
||||
|
||||
(if (= 0 (length str))
|
||||
(message "string is empty"))
|
||||
(if (/= 0 (length str))
|
||||
(message "string is not empty"))
|
||||
8
Task/Empty-string/Erlang/empty-string.erl
Normal file
8
Task/Empty-string/Erlang/empty-string.erl
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
1> S = "". % erlang strings are actually lists, so the empty string is the same as the empty list [].
|
||||
[]
|
||||
2> length(S).
|
||||
0
|
||||
3> case S of [] -> empty; [H|T] -> not_empty end.
|
||||
empty
|
||||
4> case "aoeu" of [] -> empty; [H|T] -> not_empty end.
|
||||
not_empty
|
||||
15
Task/Empty-string/Euphoria/empty-string.euphoria
Normal file
15
Task/Empty-string/Euphoria/empty-string.euphoria
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
sequence s
|
||||
|
||||
-- assign an empty string
|
||||
s = ""
|
||||
|
||||
-- another way to assign an empty string
|
||||
s = {} -- "" and {} are equivalent
|
||||
|
||||
if not length(s) then
|
||||
-- string is empty
|
||||
end if
|
||||
|
||||
if length(s) then
|
||||
-- string is not empty
|
||||
end if
|
||||
8
Task/Empty-string/F-Sharp/empty-string.fs
Normal file
8
Task/Empty-string/F-Sharp/empty-string.fs
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
open System
|
||||
|
||||
[<EntryPoint>]
|
||||
let main args =
|
||||
let emptyString = String.Empty // or any of the literals "" @"" """"""
|
||||
printfn "Is empty %A: %A" emptyString (emptyString = String.Empty)
|
||||
printfn "Is not empty %A: %A" emptyString (emptyString <> String.Empty)
|
||||
0
|
||||
1
Task/Empty-string/Factor/empty-string-1.factor
Normal file
1
Task/Empty-string/Factor/empty-string-1.factor
Normal file
|
|
@ -0,0 +1 @@
|
|||
"" empty? .
|
||||
6
Task/Empty-string/Factor/empty-string-2.factor
Normal file
6
Task/Empty-string/Factor/empty-string-2.factor
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
USE: locals
|
||||
[let
|
||||
"" :> empty-string
|
||||
empty-string empty? .
|
||||
empty-string empty? not .
|
||||
]
|
||||
5
Task/Empty-string/Fantom/empty-string.fantom
Normal file
5
Task/Empty-string/Fantom/empty-string.fantom
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
a := "" // assign an empty string to 'a'
|
||||
a.isEmpty // method on sys::Str to check if string is empty
|
||||
a.size == 0 // what isEmpty actually checks
|
||||
a == "" // alternate check for an empty string
|
||||
!a.isEmpty // check that a string is not empty
|
||||
6
Task/Empty-string/Forth/empty-string.fth
Normal file
6
Task/Empty-string/Forth/empty-string.fth
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
\ string words operate on the address and count left on the stack by a string
|
||||
\ ? means the word returns a true/false flag on the stack
|
||||
|
||||
: empty? ( c-addr u -- ? ) nip 0= ;
|
||||
: filled? ( c-addr u -- ? ) empty? 0= ;
|
||||
: ="" ( c-addr u -- ) drop 0 ; \ It's OK to copy syntax from other languages
|
||||
11
Task/Empty-string/Fortran/empty-string.f
Normal file
11
Task/Empty-string/Fortran/empty-string.f
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
SUBROUTINE TASTE(T)
|
||||
CHARACTER*(*) T !This form allows for any size.
|
||||
IF (LEN(T).LE.0) WRITE(6,*) "Empty!"
|
||||
IF (LEN(T).GT.0) WRITE(6,*) "Not empty!"
|
||||
END
|
||||
CHARACTER*24 TEXT
|
||||
CALL TASTE("")
|
||||
CALL TASTE("This")
|
||||
TEXT = "" !Fills the entire variable with space characters.
|
||||
CALL TASTE(TEXT) !Passes all 24 of them. Result is Not empty!
|
||||
END
|
||||
1
Task/Empty-string/Free-Pascal/empty-string-1.pas
Normal file
1
Task/Empty-string/Free-Pascal/empty-string-1.pas
Normal file
|
|
@ -0,0 +1 @@
|
|||
s := '';
|
||||
2
Task/Empty-string/Free-Pascal/empty-string-2.pas
Normal file
2
Task/Empty-string/Free-Pascal/empty-string-2.pas
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
s = ''
|
||||
length(s) = 0
|
||||
3
Task/Empty-string/Free-Pascal/empty-string-3.pas
Normal file
3
Task/Empty-string/Free-Pascal/empty-string-3.pas
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
s <> ''
|
||||
length(s) > 0
|
||||
longBool(length(s))
|
||||
17
Task/Empty-string/FreeBASIC/empty-string.basic
Normal file
17
Task/Empty-string/FreeBASIC/empty-string.basic
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
' FB 1.05.0 Win64
|
||||
|
||||
Sub IsEmpty(s As String)
|
||||
If Len(s) = 0 Then
|
||||
Print "String is empty"
|
||||
Else
|
||||
Print "String is not empty"
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Dim s As String ' implicitly assigned an empty string
|
||||
IsEmpty(s)
|
||||
Dim t As String = "" ' explicitly assigned an empty string
|
||||
IsEmpty(t)
|
||||
Dim u As String = "not empty"
|
||||
IsEmpty(u)
|
||||
Sleep
|
||||
6
Task/Empty-string/Frink/empty-string.frink
Normal file
6
Task/Empty-string/Frink/empty-string.frink
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
a = ""
|
||||
if a == ""
|
||||
println["empty"]
|
||||
|
||||
if a != ""
|
||||
println["Not empty"]
|
||||
17
Task/Empty-string/FutureBasic/empty-string.basic
Normal file
17
Task/Empty-string/FutureBasic/empty-string.basic
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
window 1, @"Empty string", (0,0,480,270)
|
||||
|
||||
CFStringRef s
|
||||
|
||||
s = @""
|
||||
if ( fn StringIsEqual( s, @"" ) ) then print @"string is empty"
|
||||
if ( fn StringLength( s ) == 0 ) then print @"string is empty"
|
||||
if ( len(s) == 0 ) then print @"string is empty"
|
||||
|
||||
print
|
||||
|
||||
s = @"Hello"
|
||||
if ( fn StringIsEqual( s, @"" ) == NO ) then print @"string not empty"
|
||||
if ( fn StringLength( s ) != 0 ) then print @"string not empty"
|
||||
if ( len(s) != 0 ) then print @"string not empty"
|
||||
|
||||
HandleEvents
|
||||
9
Task/Empty-string/GW-BASIC/empty-string.basic
Normal file
9
Task/Empty-string/GW-BASIC/empty-string.basic
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
10 DIM S1$ 'implicitly defined empty string
|
||||
20 S2$ = "" 'explicitly defined empty string
|
||||
30 S3$ = "Foo bar baz"
|
||||
40 S$=S1$ : GOSUB 200
|
||||
50 S$=S2$ : GOSUB 200
|
||||
60 S$=S3$ : GOSUB 200
|
||||
70 END
|
||||
200 IF LEN(S$)=0 THEN PRINT "Empty string" ELSE PRINT "Non-empty string"
|
||||
210 RETURN
|
||||
15
Task/Empty-string/Gambas/empty-string.gambas
Normal file
15
Task/Empty-string/Gambas/empty-string.gambas
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
Public Sub Main()
|
||||
Dim sString As String[] = ["", "Hello", "world", "", "Today", "Tomorrow", "", "", "End!"]
|
||||
Dim sTemp As String
|
||||
Dim siCount As Short
|
||||
|
||||
For Each sTemp In sString
|
||||
If sString[siCount] Then
|
||||
Print "String " & siCount & " = " & sString[siCount]
|
||||
Else
|
||||
Print "String " & siCount & " is empty"
|
||||
End If
|
||||
Inc siCount
|
||||
Next
|
||||
|
||||
End
|
||||
14
Task/Empty-string/Go/empty-string-1.go
Normal file
14
Task/Empty-string/Go/empty-string-1.go
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
// define and initialize an empty string
|
||||
var s string
|
||||
s2 := ""
|
||||
|
||||
// assign an empty string to a variable
|
||||
s = ""
|
||||
|
||||
// check that a string is empty, any of:
|
||||
s == ""
|
||||
len(s) == 0
|
||||
|
||||
// check that a string is not empty, any of:
|
||||
s != ""
|
||||
len(s) != 0 // or > 0
|
||||
23
Task/Empty-string/Go/empty-string-2.go
Normal file
23
Task/Empty-string/Go/empty-string-2.go
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func test(s string) {
|
||||
if len(s) == 0 {
|
||||
fmt.Println("empty")
|
||||
} else {
|
||||
fmt.Println("not empty")
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
// assign an empty string to a variable.
|
||||
str1 := ""
|
||||
str2 := " "
|
||||
// check if a string is empty.
|
||||
test(str1) // prt empty
|
||||
// check that a string is not empty.
|
||||
test(str2) // prt not empty
|
||||
}
|
||||
5
Task/Empty-string/Groovy/empty-string.groovy
Normal file
5
Task/Empty-string/Groovy/empty-string.groovy
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
def s = '' // or "" if you wish
|
||||
assert s.empty
|
||||
|
||||
s = '1 is the loneliest number'
|
||||
assert !s.empty
|
||||
8
Task/Empty-string/Harbour/empty-string.harbour
Normal file
8
Task/Empty-string/Harbour/empty-string.harbour
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
// in Harbour we have several functions to check emptiness of a string, f.e. hb_IsNull(), Len(), Empty() et.c.,
|
||||
// we can also use comparison expressions like [cString == ""] and [cString != ""], yet the most convenient
|
||||
// of them is `Empty()` (but that depends on personal coding style).
|
||||
cString := ""
|
||||
? Empty( cString ) // --> TRUE
|
||||
IF ! Empty( cString ) // --> FALSE
|
||||
? cString
|
||||
ENDIF
|
||||
10
Task/Empty-string/Haskell/empty-string.hs
Normal file
10
Task/Empty-string/Haskell/empty-string.hs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
import Control.Monad
|
||||
|
||||
-- In Haskell strings are just lists (of characters), so we can use the function
|
||||
-- 'null', which applies to all lists. We don't want to use the length, since
|
||||
-- Haskell allows infinite lists.
|
||||
|
||||
main = do
|
||||
let s = ""
|
||||
when (null s) (putStrLn "Empty.")
|
||||
when (not $ null s) (putStrLn "Not empty.")
|
||||
12
Task/Empty-string/HolyC/empty-string.holyc
Normal file
12
Task/Empty-string/HolyC/empty-string.holyc
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
/* assign an empty string */
|
||||
U8 *str = StrNew("");
|
||||
/* or */
|
||||
U8 *str = "";
|
||||
|
||||
/* to test if string is empty */
|
||||
if (StrLen(str) == 0) { ... }
|
||||
/* or compare to a known empty string. "== 0" means strings are equal */
|
||||
if (StrCmp(str, "") == 0) { ... }
|
||||
|
||||
/* to test if string is not empty */
|
||||
if (StrLen(str)) { ... }
|
||||
13
Task/Empty-string/I/empty-string.i
Normal file
13
Task/Empty-string/I/empty-string.i
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
software {
|
||||
s = ""
|
||||
|
||||
// Can either compare the string to an empty string or
|
||||
// test if the length is zero.
|
||||
if s = "" or #s = 0
|
||||
print("Empty string!")
|
||||
end
|
||||
|
||||
if s - "" or #s - 0
|
||||
print("Not an empty string!")
|
||||
end
|
||||
}
|
||||
3
Task/Empty-string/IS-BASIC/empty-string.basic
Normal file
3
Task/Empty-string/IS-BASIC/empty-string.basic
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
10 LET A$=""
|
||||
20 IF A$="" THEN PRINT "The string is empty."
|
||||
30 IF A$<>"" THEN PRINT "The string is not empty."
|
||||
16
Task/Empty-string/Icon/empty-string.icon
Normal file
16
Task/Empty-string/Icon/empty-string.icon
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
s := "" # null string
|
||||
s := string('A'--'A') # ... converted from cset difference
|
||||
s := char(0)[0:0] # ... by slicing
|
||||
|
||||
s1 == "" # lexical comparison, could convert s1 to string
|
||||
s1 === "" # comparison won't force conversion
|
||||
*s1 = 0 # zero length, however, *x is polymorphic
|
||||
*string(s1) = 0 # zero length string
|
||||
|
||||
s1 ~== "" # non null strings comparisons
|
||||
s1 ~=== ""
|
||||
*string(s1) ~= 0
|
||||
|
||||
s := &null # NOT a null string, null type
|
||||
/s # test for null type
|
||||
\s # test for non-null type
|
||||
5
Task/Empty-string/J/empty-string-1.j
Normal file
5
Task/Empty-string/J/empty-string-1.j
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
variable=: ''
|
||||
0=#variable
|
||||
1
|
||||
0<#variable
|
||||
0
|
||||
7
Task/Empty-string/J/empty-string-2.j
Normal file
7
Task/Empty-string/J/empty-string-2.j
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
''
|
||||
|
||||
EMPTY
|
||||
$''
|
||||
0
|
||||
$EMPTY
|
||||
0 0
|
||||
6
Task/Empty-string/Java/empty-string.java
Normal file
6
Task/Empty-string/Java/empty-string.java
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
String s = "";
|
||||
if(s != null && s.isEmpty()){//optionally, instead of "s.isEmpty()": "s.length() == 0" or "s.equals("")"
|
||||
System.out.println("s is empty");
|
||||
}else{
|
||||
System.out.println("s is not empty");
|
||||
}
|
||||
2
Task/Empty-string/JavaScript/empty-string-1.js
Normal file
2
Task/Empty-string/JavaScript/empty-string-1.js
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
var s = "";
|
||||
var s = new String();
|
||||
4
Task/Empty-string/JavaScript/empty-string-2.js
Normal file
4
Task/Empty-string/JavaScript/empty-string-2.js
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
s == ""
|
||||
s.length == 0
|
||||
!s
|
||||
!Boolean(s)
|
||||
5
Task/Empty-string/JavaScript/empty-string-3.js
Normal file
5
Task/Empty-string/JavaScript/empty-string-3.js
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
!!s
|
||||
s != ""
|
||||
s.length != 0
|
||||
s.length > 0
|
||||
Boolean(s)
|
||||
1
Task/Empty-string/Jq/empty-string-1.jq
Normal file
1
Task/Empty-string/Jq/empty-string-1.jq
Normal file
|
|
@ -0,0 +1 @@
|
|||
"" as $x
|
||||
3
Task/Empty-string/Jq/empty-string-2.jq
Normal file
3
Task/Empty-string/Jq/empty-string-2.jq
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
s == ""
|
||||
# or:
|
||||
s|length == 0
|
||||
3
Task/Empty-string/Jq/empty-string-3.jq
Normal file
3
Task/Empty-string/Jq/empty-string-3.jq
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
s != ""
|
||||
# or:
|
||||
s.length != 0 # etc.
|
||||
49
Task/Empty-string/Jsish/empty-string.jsish
Normal file
49
Task/Empty-string/Jsish/empty-string.jsish
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
/* Empty string, in Jsish */
|
||||
var em1 = '';
|
||||
var em2 = new String();
|
||||
|
||||
var str = 'non-empty';
|
||||
|
||||
;'Empty string tests';
|
||||
;em1 == '';
|
||||
;em1 === '';
|
||||
;em1.length == 0;
|
||||
;!em1;
|
||||
;(em1) ? false : true;
|
||||
;Object.is(em1, '');
|
||||
;Object.is(em1, new String());
|
||||
|
||||
;'Non empty string tests';
|
||||
;str != '';
|
||||
;str !== '';
|
||||
;str.length != 0;
|
||||
;str.length > 0;
|
||||
;!!str;
|
||||
;(str) ? true : false;
|
||||
|
||||
;'Compare two empty strings';
|
||||
;(em1 == em2);
|
||||
;(em1 === em2);
|
||||
|
||||
/*
|
||||
=!EXPECTSTART!=
|
||||
'Empty string tests'
|
||||
em1 == '' ==> true
|
||||
em1 === '' ==> true
|
||||
em1.length == 0 ==> true
|
||||
!em1 ==> true
|
||||
(em1) ? false : true ==> true
|
||||
Object.is(em1, '') ==> true
|
||||
Object.is(em1, new String()) ==> true
|
||||
'Non empty string tests'
|
||||
str != '' ==> true
|
||||
str !== '' ==> true
|
||||
str.length != 0 ==> true
|
||||
str.length > 0 ==> true
|
||||
!!str ==> true
|
||||
(str) ? true : false ==> true
|
||||
'Compare two empty strings'
|
||||
(em1 == em2) ==> true
|
||||
(em1 === em2) ==> true
|
||||
=!EXPECTEND!=
|
||||
*/
|
||||
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