How do you ceck if a variable is empty ? It could contain a "\n"
or spaces.
I am currently doing this
if {{string trimleft $var} != ""} {
# the variable is not empty
puts $var
}
However the variable printed still seems to be empty ? will trimleft
remove "\n"
?
Is there a better approach to check if a string is empty ?
To answer the original question with a concern of checking for an empty line here is the corrected code example:
if {[string trim $var] != ""} {
puts $var
}
Without specifying the ?chars? the trim will remove white space chars which are considered to be space, tab, newline and carriage return.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With