Empty string: Difference between revisions

Content added Content deleted
(→‎{{header|C sharp}}: Added additional explanation)
Line 28: Line 28:


The check for a non-empty string is the same, but with "not" after the n:=
The check for a non-empty string is the same, but with "not" after the n:=

=={{header|ACL2}}==
=={{header|ACL2}}==
To check if a string is empty:
To check if a string is empty:
Line 272: Line 273:
30 IF A$<>"" THEN PRINT "THE STRING IS NOT EMPTY"
30 IF A$<>"" THEN PRINT "THE STRING IS NOT EMPTY"
40 END</lang>
40 END</lang>

==={{header|Applesoft BASIC}}===
==={{header|Applesoft BASIC}}===
The terminating quote may be left off. By default, strings are initially empty so the assignment is not necessary. Another way to check for an empty string is to use the LEN function.
The terminating quote may be left off. By default, strings are initially empty so the assignment is not necessary. Another way to check for an empty string is to use the LEN function.
Line 620: Line 622:
Is not 's' empty?:> $FALSE
Is not 's' empty?:> $FALSE
</pre>
</pre>

=={{header|D}}==
=={{header|D}}==
D treats null strings and empty strings as equal on the value level, but different on object level. You need to take this into account when checking for emptiness.
D treats null strings and empty strings as equal on the value level, but different on object level. You need to take this into account when checking for emptiness.
Line 663: Line 666:
}
}
}</lang>
}</lang>

=={{header|Déjà Vu}}==
=={{header|Déjà Vu}}==
Like in Python, empty strings are falsy, non-empty strings are truthy.
Like in Python, empty strings are falsy, non-empty strings are truthy.
Line 914: Line 918:
String is not empty
String is not empty
</pre>
</pre>

=={{header|Free Pascal}}==
Assigning an empty string:
<lang pascal>s := '';</lang>
Checking for an empty string:
<lang pascal>s = ''
length(s) = 0</lang>
Checking for a non-empty string:
<lang pascal>s <> ''
length(s) > 0
longBool(length(s))</lang>
The <code>sysUtils</code> unit defines the constants <code>emptyStr</code> and <code>emptyWideStr</code>, which can be used in place of <code>&#39;&#39;</code>.


=={{header|FutureBasic}}==
=={{header|FutureBasic}}==
Line 1,764: Line 1,780:


=={{header|Pascal}}==
=={{header|Pascal}}==
See [[Empty_string#Delphi | Delphi]]
''See [[#Delphi|Delphi]] or [[#Free Pascal|Free Pascal]]''


=={{header|Perl}}==
=={{header|Perl}}==
Line 1,939: Line 1,955:
if (isEmpty(s)) print("string s is empty");
if (isEmpty(s)) print("string s is empty");
if (isEmpty(s)) print("string s is not empty");</lang>
if (isEmpty(s)) print("string s is not empty");</lang>

=={{header|Red}}==
=={{header|Red}}==
<lang Red>Red []
<lang Red>Red []
Line 1,953: Line 1,970:
>>
>>
</pre>
</pre>

=={{header|Retro}}==
=={{header|Retro}}==
Create an empty string and assign it to a variable. In these '''keepString''' is used to ensure that the string is permanent.
Create an empty string and assign it to a variable. In these '''keepString''' is used to ensure that the string is permanent.
Line 2,031: Line 2,049:
ok
ok
</lang>
</lang>

=={{header|Ruby}}==
=={{header|Ruby}}==


Line 2,264: Line 2,283:
out "not empty" endl console
out "not empty" endl console
end if</lang>
end if</lang>

=={{header|VAX Assembly}}==
=={{header|VAX Assembly}}==


Line 2,276: Line 2,296:
ret
ret
.end empty</lang>
.end empty</lang>

=={{header|VBA}}==
=={{header|VBA}}==
<lang vb>
<lang vb>