Reputation: 137
I have a variable nodename = v445
and another variable nodepatch=v445-sctpsv
I want to compare as
if { $nodename == ???????} {
}
so here I just want to compare only part before certain -
the second variable could contain more than one - in name, so I just want to extract equivalent string to nodename to compare with.
after string manipulation second part should come up like this:
if { $nodename == "v445"} {
proceed } else {
}
Upvotes: 1
Views: 2862
Reputation: 13252
Try
set nodename v445
set nodepatch v445-sctpsv
if {[string match $nodename* $nodepatch]} {
proceed
} else {
}
string match
does a glob-style match against a string, in this case the string that starts with the value in $nodename
and contains zero or more characters is matched against the string $nodepatch
.
If you need to ensure that the dash occurs, use string match $nodename-* $nodepatch
instead.
Documentation: if, set, string
Upvotes: 2