Reputation: 3287
I have a string in tcl like this:
set hello 0x09
how to get the last part of $hello
, like 09
from it?
Upvotes: 0
Views: 246
Reputation: 2947
The simplest answer to your question would be:
set result [lindex [split $hello "x"] 1]
Depending on your problem, this solution might not be the best. What is it you are trying to do?
Upvotes: 1
Reputation: 247210
You could evaluate the string in a slave interpreter, and rely on the fact that the set
command returns its value:
set cmd {set hello 0x09}
set i [interp create -safe]
set value [interp eval $i $cmd]
puts $value
0x09
This also protects you from set hello [exec echo malicious command here]
Upvotes: 0