Hi I have a string
variable in tcl that stores some integer
value. I need to get the left most digit from the string
variable and increment it by 1. Basically below is the code that I wrote to accomplish my task :
set maxID 123456;
if {$maxID < 1000000} {
set maxID 1000000;
} elseif {$maxID >= 1000000} {
set maxID [expr [string index $maxID 0] + 1]000000; #Need to Simplify this
}
return $maxID;
Now what I am trying to do is if the maxID
is greater than or equal to 1 million, set the maxID
to the next million value. So in above example since maxID
is 123456
, the return maxID
value should be 1000000
since the next million value for 123456
is 1000000
.
So to do that, I am getting the left most digit which is 1, then increment it by 1 and concat six zeros which will increment the value. I am using tcl 8.5.x so I still don't have [string cat $args $args...]
command available.
Anyways, I was wondering if there is any simpler way of doing the same.