Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if a variable is empty in tcl

Tags:

tcl

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 ?

like image 245
Rajeshwar Avatar asked Dec 12 '14 22:12

Rajeshwar


1 Answers

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.

like image 82
Earnie Avatar answered Nov 23 '22 08:11

Earnie