Aman Kapoor
Aman Kapoor

Reputation: 21

To check if string A matching String B exactly in Tcl

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

Answers (1)

Onel Sarmiento
Onel Sarmiento

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 $Band $A. Returns -1, 0, or 1, depending on whether $Bis 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

Related Questions