0

I have a string in tcl like this:

set hello 0x09 

how to get the last part of $hello, like 09 from it?

2
  • 1
    What have you tried to far? We don't do someone else's homework here but we're pleased to help with concrete problems, so what have you tried? Please, be more specific and descriptive. Commented Jul 29, 2013 at 16:26
  • Well, is the string 0x09 or set hello 0x09? If it is 0x09 it is an integer (do what you want with it). If it is the later eval it in a safe interp. Commented Jul 30, 2013 at 9:25

2 Answers 2

1

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?

Sign up to request clarification or add additional context in comments.

Comments

0

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]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.