Empty string: Difference between revisions

removed langur language example for now
(Adds slope example)
(removed langur language example for now)
 
(19 intermediate revisions by 11 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 628 ⟶ 666:
REM Check that a string is not empty:
IF var$ <> "" THEN PRINT "String is not empty"
</syntaxhighlight>
 
=={{header|Beef}}==
<syntaxhighlight lang="csharp">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");
}
}
}
}
</syntaxhighlight>
 
Line 1,220 ⟶ 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,622 ⟶ 1,711:
 
=={{header|jq}}==
jq programs can read JSON strings as data and may contain JSON strings. This entry is focused on such strings and excludes from consideration interpolation directives, which have the form of strings but are not themselves valid JSON strings.
jq strings are JSON strings. The empty string literal is simply <tt>""</tt>. It can be assigned to a variable as illustrated by this example:<syntaxhighlight lang="jq">"" as $x </syntaxhighlight>If s is a string or an array, then the additive "zero" for s can be created by writing s[0:0]. That is, if s is a string, then s[0:0] will yield the empty string. This is useful when writing polymorphic functions.
 
The empty string literal is simply <tt>""</tt>. It can be assigned to a variable as illustrated by this example:<syntaxhighlight lang="jq">"" as $x </syntaxhighlight>If s is a string or an array, then the additive "zero" for s can be created by writing s[0:0]. That is, if s is a string, then s[0:0] will yield the empty string. This is useful when writing polymorphic functions.
 
To determine whether a string, s, is empty:<syntaxhighlight lang="jq">s == ""
Line 1,769 ⟶ 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,062 ⟶ 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,439 ⟶ 2,571:
<span style="color: #008080;">if</span> <span style="color: #000000;">s</span><span style="color: #0000FF;">!=</span><span style="color: #008000;">""</span> <span style="color: #008080;">then</span> <span style="color: #000080;font-style:italic;">-- string is not empty</span>
<!--</syntaxhighlight>-->
 
=={{header|Phixmonti}}==
<syntaxhighlight lang="Phixmonti">/# Rosetta Code problem: http://rosettacode.org/wiki/Empty_string
by Galileo, 10/2022 #/
 
"" var s
s len if "String is NOT empty" else "String IS empty" endif print nl
" " "" == if "String IS empty" else "String is NOT empty" endif print
</syntaxhighlight>
{{out}}
<pre>String IS empty
String is NOT empty
=== Press any key to exit ===</pre>
 
=={{header|PHP}}==
Line 2,792 ⟶ 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,283 ⟶ 3,444:
False</pre>
 
=={{header|V (Vlang)}}==
<syntaxhighlight lang="v (vlang)">// define and initialize an empty string
mut s := ""
 
Line 3,325 ⟶ 3,486:
 
=={{header|Wren}}==
<syntaxhighlight lang="ecmascriptwren">var isEmpty = Fn.new { |s| s == "" }
 
var s = ""
Line 3,460 ⟶ 3,621:
}
if (str.len != 0) {
std.debug.print("string not empty\n", .{});
}
}</syntaxhighlight>
885

edits