Jump to content

Empty string: Difference between revisions

→‎Tcl: Added implementation
(→‎Tcl: Added implementation)
Line 93:
if s:
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>
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.