Reputation: 1892
I have a function which returns me string into following way
% set b [le::splitIntoBoxes $m1_drw -type maxX]
{1.154 0.068 1.222 0.518} {1.154 0.518 1.370 0.562}
I would like split string and store values in x1 y1 x2 y2. I have tried all option but not able to fix issue
% puts [regexp -all -inline {\S+} $b]
\{1.154 0.068 1.222 0.518\} \{1.154 0.518 1.370 0.562\}
I would like to ignore "\" so I can store values in x1 y1 x2 y2.
Upvotes: 0
Views: 378
Reputation: 1641
You can do this:
% proc mysplit d {
concat {*}$d
}
% set b {{1.154 0.068 1.222 0.518} {1.154 0.518 1.370 0.562}}
{1.154 0.068 1.222 0.518} {1.154 0.518 1.370 0.562}
% mysplit [mysplit $b]
1.154 0.068 1.222 0.518 1.154 0.518 1.370 0.562
Upvotes: 1
Reputation: 3003
Looks like you have a string as returned and have to parse it as al list of lists.
So for example:
foreach token $b {
foreach {x1 y1 x2 y2} $token {break;}
puts "x1 $x1 y1 $y2 x2 $x2 y2 $y2"
}
The first foreach 'split' the string in chunks on spaces.
Than you have chunks like:
{1.154 0.068 1.222 0.518}
That is a list itself, in the second loop you're going to assign each element of this list to your designed variables.
Upvotes: 3