Empty string: Difference between revisions
Content added Content deleted
m (→{{header|UNIX Shell}}: typo) |
(add Ruby) |
||
Line 318: | Line 318: | ||
if s: |
if s: |
||
print('String s is not empty.')</lang> |
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}}== |
=={{header|Seed7}}== |