Version 3 of string compare ...

Updated 2002-03-21 18:50:47

I've no idea why someone thought this page might be useful... RS thinks that in some page [string compare ...] was written with single brackets, which open a potential new page if somebody clicks on the blue brackets. But now that we have this page, comparing strings can be done in various ways:

 if {$name=="foo"} {...}                  ;# (1)
 if {$name eq "foo} {...}                 ;# (2)
 if {[string compare $name foo]==0} {...} ;# (3)
 if {[string equal $name foo]} {...}      ;# (4)

(1) is the classic overloading of comparison operators in expr to work also on non-numeric strings, but first tries numeric, including the various number bases, so

 8 == 010
 0xF == 15 == 017

(2) is new string comparison operators from 8.4 or so

(3) used to be recommended, but is so wordy...

(4) is recommended since 8.3 or so