Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

string manipulation

Status
Not open for further replies.

sl1200mk2

Technical User
Jun 7, 2005
39
FR
hi all

how to deal with that
here's the string
step0mem0time-in0time-out0delay-in0delay-out0wait0nullstep1mem1time-in2time-out2delay-in0delay-out0wait0nullstep2mem2time-in2time-out2delay-in0delay-out0wait1null

i would like to get
step 0 mem 0 time-in 0 time-out 0 delay-in 0 delay-out 0 wait 0
step 1 mem 1 time-in......

i've put the "null" char to prmit a \n
what i don't know to do is spacing word of num

any helps are welcome, as usual....
best regards

nico
 
I think a 2-step process using regsub:
First, we'll call the string you're parsing, "instr":
set instr step0mem0time-in0time-out0delay-in0delay-out0wait0nullstep1mem1time-in2time-out2delay-in0delay-out0wait0nullstep2mem2time-in2time-out2delay-in0delay
-out0wait1null


Next, we'll use regsub to put a space every time a letter is followed by a digit:
regsub -all {(\w)(\d)} $instr "\\1 \\2" outstr
and put the output in "outstr"

Next, we put a space every time a digit is followed by a letter:
regsub -all {(\d)(\w)} $outstr "\\1 \\2" outstr
and the output is still in "outstr"

the result is:
step 0 mem 0 time-in 0 time-out 0 delay-in 0 delay-out 0 wait 0 nullstep 1 mem 1 time-in 2 time-out 2 delay-in 0 delay-out 0 wait 0 nullstep 2 mem 2 time-in 2 time-out 2 delay-in 0 delay-out 0 wait 1 null

_________________
Bob Rashkin
rrashkin@csc.com
 
bong, you're at the top

let's organize a "Summer Tcl Beach Festival......."
with music and computer....

many thanks
 
still many thanks

what we have done:
parse an xml file in a text widget
make readable by anyone
save it back in xml format
and parse it again.....

well done
 
one more thing:
i've tried with step 200 for example....

it display
step 2 0 0
and not
step 200

it doesn't really matter because my xml formatter understand 200
but....

do you have an idea?
 
Well, I'm not really very good with RE_syntax. I think "\w" is alphanumeric, not just alpha, which would explain the behavior. Maybe if you substitute "[a-zA-z]" for "\\w" it would work better?

_________________
Bob Rashkin
rrashkin@csc.com
 
perhaps you're not really very good, but you're very good with RE_

it was the solution...

well done
best regards

nico
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top