Empty string: Difference between revisions

removed langur language example for now
(→‎{{header|Vlang}}: Rename "Vlang" in "V (Vlang)")
(removed langur language example for now)
 
(11 intermediate revisions by 7 users not shown)
Line 530:
call IsEmpty (u$)
end</syntaxhighlight>
 
==={{header|Chipmunk Basic}}===
{{works with|Chipmunk Basic|3.6.4}}
<syntaxhighlight lang="qbasic">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</syntaxhighlight>
 
==={{header|IS-BASIC}}===
Line 535 ⟶ 553:
20 IF A$="" THEN PRINT "The string is empty."
30 IF A$<>"" THEN PRINT "The string is not empty."</syntaxhighlight>
 
==={{header|MSX Basic}}===
{{works with|Applesoft BASIC}}
{{works with|Chipmunk Basic}}
{{works with|GW-BASIC}}
{{works with|PC-BASIC}}
{{works with|QBasic}}
{{works with|Quite BASIC}}
<syntaxhighlight lang="qbasic">100 CLS : REM 100 HOME for Applesoft BASIC
110 LET S$ = ""
120 GOSUB 160
130 LET S$ = "not empty"
140 GOSUB 160
150 END
160 REM isEmpty
170 IF LEN(S$) = 0 THEN PRINT "String is empty"
180 IF LEN(S$) <> 0 THEN PRINT "String is not empty"
190 IF S$ = "" THEN PRINT "yes, the string is empty"
200 IF S$ <> "" THEN PRINT "no, the string is not empty"
210 RETURN</syntaxhighlight>
 
==={{header|QB64}}===
Line 1,243 ⟶ 1,281:
 
Also possible is <code>(string= "" str)</code>.
 
An common lisp incompatible way:
<syntaxhighlight lang="lisp">
(defvar str "" "An empty string")
 
(if (length= str 0)
(message "string is empty")
(message "string is not empty"))
</syntaxhighlight>
 
=={{header|EMal}}==
<syntaxhighlight lang="emal">
# Demonstrate how to assign an empty string to a variable.
text sampleA = Text.EMPTY
text sampleB = "hello world"
text sampleC = ""
List samples = text[sampleA, sampleB, sampleC]
for each text sample in samples
# Demonstrate how to check that a string is empty.
writeLine("Is '" + sample + "' empty? " + when(sample.isEmpty(), "Yes", "No") + ".")
end
</syntaxhighlight>
{{out}}
<pre>
Is '' empty? Yes.
Is 'hello world' empty? No.
Is '' empty? Yes.
</pre>
 
=={{header|Erlang}}==
Line 1,794 ⟶ 1,860:
</syntaxhighlight>
 
=={{header|langur}}==
You can use empty quote marks or the ZLS token.
<syntaxhighlight lang="langur">val .zls = ZLS
writeln .zls == ""
writeln .zls != ""
writeln len(.zls)</syntaxhighlight>
 
=={{outheader|Lang}}==
In Lang strings are called text and are of type TEXT.
<pre>true
<syntaxhighlight lang="lang">
false
# Text creation
0</pre>
# Empty text escape sequence
$s = \e
$s = {{{}}}
# With simple assignment:
$s=
 
# "$s =" would not work, as ist would set $s to null
 
# Is empty
fn.println(parser.con($s == \e))
fn.println(parser.con($s === \e))
fn.println(parser.con(!$s))
fn.println(fn.conNot($s))
fn.println(parser.con(fn.strlen($s) == 0))
fn.println(parser.con(fn.len($s) == 0))
fn.println(parser.op(@$s == 0))
 
# Is not empty
fn.println(parser.con($s != \e))
fn.println(parser.con($s !== \e))
fn.println(parser.con($s)) # Must be used in conditional parsing mode (Execution parsing mode would return $s as is)
fn.println(fn.bool($s))
fn.println(parser.con(fn.strlen($s) > 0))
fn.println(parser.con(fn.len($s) > 0))
fn.println(parser.op(@$s > 0))
</syntaxhighlight>
 
=={{header|Lasso}}==
Line 2,087 ⟶ 2,173:
true
false
</pre>
 
=={{header|MiniScript}}==
{{trans|Wren}}
<syntaxhighlight lang="miniscript">string.isEmpty = function
return self == ""
end function
 
number.toBoolStr = function
if self == 0 then return "false"
return "true"
end function
 
s = ""
t = "0"
print "'s' is empty? " + s.isEmpty.toBoolStr
print "'t' is empty? " + t.isEmpty.toBoolStr</syntaxhighlight>
 
{{out}}
<pre>'s' is empty? true
't' is empty? false
</pre>
 
Line 2,830 ⟶ 2,937:
end
</syntaxhighlight>
 
=={{header|RPL}}==
===Assigning an empty string to a variable===
Here, s1 is a temporary variable that disappears at execution end: the <code>→</code> instruction both declares the variable and transfers the value at stack level 1 into it. <code>STO</code> does the same, but the syntax is different (instruction after the variable name) and the created variable is persistent.
≪ "" → s1
≪ "" 's2' STO
"something" 's3' STO
≫ ≫
===Testing if a string variable is empty===
2 methods:
IF s2 "" == THEN "Empty" END
IF s2 SIZE NOT THEN "Empty" END
===Testing if a string variable is not empty===
2 methods:
IF s3 "" ≠ THEN "Not empty" END
IF s3 SIZE THEN "Not empty" END
 
=={{header|Ruby}}==
Line 3,363 ⟶ 3,486:
 
=={{header|Wren}}==
<syntaxhighlight lang="ecmascriptwren">var isEmpty = Fn.new { |s| s == "" }
 
var s = ""
885

edits