Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,5 @@
---
category:
- String manipulation
- Simple
from: http://rosettacode.org/wiki/Empty_string

View 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>

View file

@ -0,0 +1,5 @@
V s =
I s.empty
print(String s is empty.)
I !s.empty
print(String s is not empty.)

View file

@ -0,0 +1,2 @@
EmptyString:
byte 0

View 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

View file

@ -0,0 +1,3 @@
EmptyString:
DC.B 0
EVEN

View 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.

View file

@ -0,0 +1 @@
"" var, str

View file

@ -0,0 +1 @@
str @ s:len 0 n:= if ... then

View file

@ -0,0 +1 @@
str: .asciz ""

View file

@ -0,0 +1,3 @@
mov x5, #0
ldrb w5, [x0]
cmp x5, #0

View 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

View file

@ -0,0 +1 @@
(= (length str) 0)

View 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

View file

@ -0,0 +1,6 @@
⍝⍝ Assign empty string to A
A ''
0 = A
1
~0 = A
0

View 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 */

View 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;
}

View 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

View 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;

View file

@ -0,0 +1,8 @@
text s;
s = "";
if (length(s) == 0) {
...
}
if (length(s) != 0) {
....
}

View 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.

View 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

View 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"

View 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"

View 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");
}

View 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

View file

@ -0,0 +1,5 @@
emptyStringVar : string := "";
Assert: emptyStringVar = "";
Assert: emptyStringVar = <>;
Assert: emptyStringVar is empty;
Assert: |emptyStringVar| = 0;

View file

@ -0,0 +1,5 @@
nonemptyStringVar : string := "content!";
Assert: nonemptyStringVar ≠ "";
Assert: nonemptyStringVar ≠ <>;
Assert: ¬nonemptyStringVar is empty;
Assert: |nonemptyStringVar| > 0;

View file

@ -0,0 +1 @@
Assert: nonemptyStringVar ∈ nonempty string;

View file

@ -0,0 +1,6 @@
""→Str1
!If length(Str1)
Disp "EMPTY",i
Else
Disp "NOT EMPTY",i
End

View 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

View 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

View 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"

View file

@ -0,0 +1,4 @@
•Show ""
•Show 0 = ""
•Show 0 ""
•Show ""

View file

@ -0,0 +1,4 @@
1
0
1

View file

@ -0,0 +1,4 @@
' Empty string
a$ = ""
IF a$ = "" THEN PRINT "Empty string"
IF a$ != "" THEN PRINT "Non empty string"

View 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.

View 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");
}
}
}
}

View 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 }
)

View file

@ -0,0 +1,6 @@
blsq ) ""
""
blsq ) ""nu
1
blsq ) "a"nu
0

View 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

View 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)) { }
}
}

View 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, ""));
}
}

View 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) { ... }

View 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.

View 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

View 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

View 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

View 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

View 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.

View 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());
}

View 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');

View file

@ -0,0 +1,11 @@
main() {
var empty = '';
if (empty.isEmpty) {
print('it is empty');
}
if (empty.isNotEmpty) {
print('it is not empty');
}
}

View 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.

View file

@ -0,0 +1,2 @@
add_str(s,⟦⟧); // empty string
add_str(n); // null string (␀)

View 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

View 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

View 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);

View file

@ -0,0 +1 @@
var str = ""

View file

@ -0,0 +1 @@
if str.IsEmpty() { }

View file

@ -0,0 +1 @@
if !str.IsEmpty() { }

View file

@ -0,0 +1,7 @@
a$ = ""
if a$ = ""
print "empty"
.
if a$ <> ""
print "no empty"
.

View 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") }
}

View 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

View 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"))

View 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

View 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

View 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

View file

@ -0,0 +1 @@
"" empty? .

View file

@ -0,0 +1,6 @@
USE: locals
[let
"" :> empty-string
empty-string empty? .
empty-string empty? not .
]

View 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

View 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

View 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

View file

@ -0,0 +1 @@
s := '';

View file

@ -0,0 +1,2 @@
s = ''
length(s) = 0

View file

@ -0,0 +1,3 @@
s <> ''
length(s) > 0
longBool(length(s))

View 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

View file

@ -0,0 +1,6 @@
a = ""
if a == ""
println["empty"]
if a != ""
println["Not empty"]

View 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

View 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

View 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

View 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

View 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
}

View file

@ -0,0 +1,5 @@
def s = '' // or "" if you wish
assert s.empty
s = '1 is the loneliest number'
assert !s.empty

View 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

View 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.")

View 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)) { ... }

View 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
}

View 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."

View 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

View file

@ -0,0 +1,5 @@
variable=: ''
0=#variable
1
0<#variable
0

View file

@ -0,0 +1,7 @@
''
EMPTY
$''
0
$EMPTY
0 0

View 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");
}

View file

@ -0,0 +1,2 @@
var s = "";
var s = new String();

View file

@ -0,0 +1,4 @@
s == ""
s.length == 0
!s
!Boolean(s)

View file

@ -0,0 +1,5 @@
!!s
s != ""
s.length != 0
s.length > 0
Boolean(s)

View file

@ -0,0 +1 @@
"" as $x

View file

@ -0,0 +1,3 @@
s == ""
# or:
s|length == 0

View file

@ -0,0 +1,3 @@
s != ""
# or:
s.length != 0 # etc.

View 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