2016 Update
This commit is contained in:
parent
948b86eafa
commit
dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions
|
|
@ -1,11 +1,11 @@
|
|||
Languages may have features for dealing specifically with empty strings
|
||||
(those containing no characters).
|
||||
|
||||
The task is to:
|
||||
|
||||
* 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.
|
||||
;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.
|
||||
<br><br>
|
||||
|
||||
[[Category:String manipulation]] [[Category:Simple]]
|
||||
|
|
|
|||
3
Task/Empty-string/BASIC/empty-string-2.basic
Normal file
3
Task/Empty-string/BASIC/empty-string-2.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"
|
||||
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 system.
|
||||
#import extensions.
|
||||
|
||||
#symbol program = [
|
||||
#var s := emptyLiteralValue.
|
||||
|
||||
(s is &empty)
|
||||
? [ console writeLine:"'":s:"' is empty". ].
|
||||
|
||||
(s is &nonempty)
|
||||
? [ console writeLine:"'":s:"' is not empty". ].
|
||||
].
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
!!s
|
||||
s != ""
|
||||
s.length != 0
|
||||
s.length > 0
|
||||
|
|
|
|||
6
Task/Empty-string/Kotlin/empty-string.kotlin
Normal file
6
Task/Empty-string/Kotlin/empty-string.kotlin
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
val s = ""
|
||||
println(s.isEmpty()) // true
|
||||
println(s.isNotEmpty()) // false
|
||||
println(s.length) // 0
|
||||
println(s.none()) // true
|
||||
println(s.any()) // false
|
||||
4
Task/Empty-string/PowerShell/empty-string-1.psh
Normal file
4
Task/Empty-string/PowerShell/empty-string-1.psh
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
[string]$alpha = "abcdefghijklmnopqrstuvwxyz"
|
||||
[string]$empty = ""
|
||||
# or...
|
||||
[string]$empty = [String]::Empty
|
||||
2
Task/Empty-string/PowerShell/empty-string-2.psh
Normal file
2
Task/Empty-string/PowerShell/empty-string-2.psh
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
[String]::IsNullOrEmpty($alpha)
|
||||
[String]::IsNullOrEmpty($empty)
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
[string]::IsNullOrEmpty("")
|
||||
[string]::IsNullOrEmpty("a")
|
||||
|
|
@ -1,40 +1,39 @@
|
|||
/*REXX: how to assign an empty string & then check for empty/not-empty.*/
|
||||
/*REXX program shows how to assign an empty string, & then check for empty/not-empty str*/
|
||||
|
||||
/*─────────────── 3 simple wats to assign an empty string to a variable.*/
|
||||
auk='' /*uses two single quotes or apostrophies. */
|
||||
ide="" /*uses two quotes, sometimes called a double quote.*/
|
||||
doe= /*... nothing at all. */
|
||||
/*─────────────── 3 simple ways to assign an empty string to a variable.*/
|
||||
auk='' /*uses two single quotes (also called apostrophes); easier to peruse. */
|
||||
ide="" /*uses two quotes, sometimes called a double quote. */
|
||||
doe= /*··· nothing at all (which in this case, a null value is assigned. */
|
||||
|
||||
/*─────────────── assigning multiple null values to vars, 2 methods are:*/
|
||||
ram=0
|
||||
parse var ram . emu pug yak nit moa owl pas jay koi ern ewe fae gar hob
|
||||
/*where the value of zero is skipped, the rest set to null,*/
|
||||
/*which is the next value AFTER the value of RAM (nothing).*/
|
||||
/*─────────────── assigning multiple null values to vars, 2 methods are:*/
|
||||
parse var doe emu pug yak nit moa owl pas jay koi ern ewe fae gar hob
|
||||
|
||||
/*───or─── (with less clutter ─── or more, ... perception).*/
|
||||
/*where emu, pug, yak, ··· (and the rest) are all set to a null value.*/
|
||||
|
||||
/*───or─── (with less clutter ─── or more, depending on your perception)*/
|
||||
parse value 0 with . ant ape ant imp fly tui paa elo dab cub bat ayu
|
||||
/*where the value of zero is skipped, the rest set to null,*/
|
||||
/*which is the next value AFTER the 0 (zero): nothing. */
|
||||
/*where the value of zero is skipped, and the rest are set to null,*/
|
||||
/*which is the next value AFTER the 0 (zero): nothing (or a null).*/
|
||||
|
||||
/*─────────────── how to check that a string is empty, several methods: */
|
||||
if cat=='' then say "the feline is not here."
|
||||
if pig=="" then say 'no ham today'
|
||||
if length(gnu)==0 then say "the wildebeast is empty & hungry."
|
||||
if length(ips)=0 then say "checking with == instead of = is faster"
|
||||
if length(hub)<1 then method = "obtuse, don't do as I do ..."
|
||||
/*─────────────── how to check that a string is empty, several methods: */
|
||||
if cat=='' then say "the feline is not here."
|
||||
if pig=="" then say 'no ham today.'
|
||||
if length(gnu)==0 then say "the wildebeest's stomach is empty and hungry."
|
||||
if length(ips)=0 then say "checking with == instead of = is faster"
|
||||
if length(hub)<1 then method = "this is rather obtuse, don't do as I do ···"
|
||||
|
||||
nit='' /*assign an empty string to a lice egg.*/
|
||||
if cow==nit then say 'the cow has no milk today.'
|
||||
nit='' /*assign an empty string to a lice egg.*/
|
||||
if cow==nit then say 'the cow has no milk today.'
|
||||
|
||||
/*─────────────── how to check that a string isn't empty, several ways: */
|
||||
/*─────────────── how to check that a string isn't empty, several ways: */
|
||||
if dog\=='' then say "the dogs are out!"
|
||||
/*most REXXes support the "not" character. */
|
||||
/*most REXXes support the ¬ character. */
|
||||
if fox¬=='' then say "and the fox is in the henhouse."
|
||||
if length(rat)>0 then say "the rat is singing" /*ugly way to test.*/
|
||||
if length(rat)>0 then say "the rat is singing" /*an obscure-ish (or ugly) way to test.*/
|
||||
|
||||
if elk=='' then nop; else say "long way for an elk to be tested."
|
||||
if elk=='' then nop; else say "long way obtuse for an elk to be tested."
|
||||
|
||||
if length(eel)\==0 then fish=eel /*fast compare, quick.*/
|
||||
if length(cod)\=0 then fish=cod /*not-so-fast compare.*/
|
||||
if length(eel)\==0 then fish=eel /*a fast compare (than below), & quick.*/
|
||||
if length(cod)\=0 then fish=cod /*a not-as-fast compare. */
|
||||
|
||||
/*────────────────────────── anyway, as they say: "choose your poison." */
|
||||
/*────────────────────────── anyway, as they say: "choose your poison." */
|
||||
|
|
|
|||
9
Task/Empty-string/Rust/empty-string.rust
Normal file
9
Task/Empty-string/Rust/empty-string.rust
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
let s = "";
|
||||
println!("is empty: {}", s.is_empty());
|
||||
let t = "x";
|
||||
println!("is empty: {}", t.is_empty());
|
||||
let a = String::new();
|
||||
println!("is empty: {}", a.is_empty());
|
||||
let b = "x".to_string();
|
||||
println!("is empty: {}", b.is_empty());
|
||||
println!("is not empty: {}", !b.is_empty());
|
||||
7
Task/Empty-string/SNOBOL4/empty-string.sno
Normal file
7
Task/Empty-string/SNOBOL4/empty-string.sno
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
* ASSIGN THE NULL STRING TO X
|
||||
X =
|
||||
* CHECK THAT X IS INDEED NULL
|
||||
EQ(X, NULL) :S(YES)
|
||||
OUTPUT = 'NOT NULL' :(END)
|
||||
YES OUTPUT = 'NULL'
|
||||
END
|
||||
Loading…
Add table
Add a link
Reference in a new issue