Jump to content

Empty string: Difference between revisions

add Ruby
(add Ruby)
Line 318:
if s:
print('String s is not empty.')</lang>
 
=={{header|Ruby}}==
 
Create an empty string
<lang ruby>s = ""
s = String.new
s = "any string".clear</lang>
 
These expressions all evaluate to true to determine emptiness:
<lang ruby>s == ""
s.eql?("")
s.empty?
s.length == 0
s[/^$/]
 
# also silly things like
s.each_char.to_a.empty?</lang>
 
Non-empty expressions:
<lang ruby>s != ""
s.length > 0
s[/./]</lang>
 
Note that we cannot 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>
 
=={{header|Seed7}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.