Empty string: Difference between revisions
Content added Content deleted
(→Tcl: Added implementation) |
|||
Line 93: | Line 93: | ||
if s: |
if s: |
||
print('String s is not empty.')</lang> |
print('String s is not empty.')</lang> |
||
=={{header|Tcl}}== |
|||
The only special position that the empty string has in Tcl is that a great many commands return it, and the REPL of [[tclsh]] and [[wish]] doesn't print it. Otherwise, it is just like any other value. |
|||
<lang tcl>set s "" |
|||
if {$s eq ""} {puts "s contains an empty string"} |
|||
if {$s ne ""} {phts "s contains a non-empty string"}</lang> |
|||
There are other ways to check for emptiness and non-emptiness too (though the above are favored for reasons of simplicity, clarity and speed): |
|||
<lang tcl>if {[string equal $s ""]} {puts "is empty"} |
|||
if {[string length $s] == 0} {puts "is empty"} |
|||
if {[string compare $s ""] != 0} {puts "is non-empty"}</lang> |