Reputation: 21
I have two strings in Tcl.
set A "A-1 Precision Machining"
set B "Xyz & a"
Now I want to check if my two different output is matching exactly or not.
if $A = $B
or not.
How I can check this in Tcl?
Initially I am using:
if { [string match $B $A] }
Upvotes: 1
Views: 35825
Reputation: 1626
If you want to compare the variable literally you can use
[string equal $B $A]
This will compare the string character-by-character and return 1 if $B
and $A
is identical and return 0 if not. TCL string equal
If the string is lexicographical you can use
[string compare $B $A]
This will perform a character-by-character comparison of strings $B
and $A
. Returns -1, 0, or 1, depending on whether $B
is lexicographical less than, equal to, or greater than $A
. TCL string compare
You can also use the traditional statement
if {$B == $A} {
// Codes...
}
Upvotes: 8