Forum Discussion

tony_haynes_247's avatar
tony_haynes_247
Icon for Nimbostratus rankNimbostratus
Oct 23, 2007

convert string into an integer

I need to convert a variable string "mserver_number" that contains a number"string" into an integer. I need to take that integer so I can build a loop where my loop number starts as the "mserver_number". So if I have 1 - 10 and my mserver_number equals 3 my loop number starts at 3 and goes to 10. I found some information on Tcl_GetInt from the TCL reference. But seeing how I am not experienced in TCL I am unsure how to use it. So basically I want to take "mserver_number" string and convert it to "loop_number" integer

 

 

Thanks

 

 

1 Reply

  • hoolio's avatar
    hoolio
    Icon for Cirrostratus rankCirrostratus
    Does your data literally look like mserver_2 or mswerver_10? And you're trying to parse that string to get just the digits after the underscore? If so, you can use getfield to split the string and take just the second field:

    
    set test_string mserver_9
    set digit [getfield $test_string "_" 2]
    log local0. $digit

    This logs 9. If this isn't what you meant, can you clarify?

    Thanks,

    Aaron