Empty string: Difference between revisions

Content added Content deleted
(add Zig example)
Line 1,308: Line 1,308:


=={{header|FutureBasic}}==
=={{header|FutureBasic}}==
<lang futurebasic>window 1, @"Empty string", (0,0,480,270)
FB has several ways to determine string length as demonstrated below.
Note: The length -- or number of characters -- of a Pascal string in FB is stored in the first element of the string array. Here the string is dimensioned a s, hence s[0] contains the length of the string, and any individual character in the string can be found using s[i], where i is the position of the character. This makes iterating over the individual characters in a string easier than using functions such as instr or mid$.
<lang futurebasic>
include "ConsoleWindow"


CFStringRef s
dim as Str255 s


s = ""
s = @""
if s == "" then print "String is empty"
if ( fn StringIsEqual( s, @"" ) ) then print @"string is empty"
if s[0] == 0 then print "String is empty"
if ( fn StringLength( s ) == 0 ) then print @"string is empty"
if len(s) == 0 then print "String is empty"
if ( len(s) == 0 ) then print @"string is empty"


print
s = "Hello"

if s <> "" then print "String not empty."
s = @"Hello"
if s[0] then print "String not empty."
if len(s) > 0 then print "String not empty."
if ( fn StringIsEqual( s, @"" ) == NO ) then print @"string not empty"
if ( fn StringLength( s ) != 0 ) then print @"string not empty"
</lang>
if ( len(s) != 0 ) then print @"string not empty"

HandleEvents</lang>


=={{header|Gambas}}==
=={{header|Gambas}}==