Empty string: Difference between revisions

Content added Content deleted
(Ruby: Let the regular expressions work when string contains newlines "\n".)
Line 738: Line 738:
s.empty?
s.empty?
s.length == 0
s.length == 0
s[/^$/]
s[/\A\z/]


# also silly things like
# also silly things like
Line 746: Line 746:
<lang ruby>s != ""
<lang ruby>s != ""
s.length > 0
s.length > 0
s[/./]</lang>
s[/./m]</lang>


Note that we can '''not''' do the following, because the empty string is equivalent to true in Ruby ([[Boolean values#Ruby]]):
Note that we can '''not''' do the following, because the empty string is equivalent to true in Ruby ([[Boolean values#Ruby]]):
<lang ruby>if s then puts "not empty" end</lang>
<lang ruby>if s then puts "not empty" end # This code is wrong!</lang>

=={{header|Run BASIC}}==
=={{header|Run BASIC}}==
<lang runbasic>var$ = ""
<lang runbasic>var$ = ""