How to seperate strings and numbers seperately?

greenspun.com : LUSENET : Tool Command Language (Tcl) : One Thread

I have the following inputs:

fa5/1-4,fa3/4-7,e4/23,e3/3-5

how do i get this as output: in list format: {5/1 5/2 5/3 5/4 3/4 3/5 3/6 3/7 4/23 3/3 3/4 3/5}

Note: 1-4 mean 1,2,3,4

-- Yusuf (ayubsyz@hotmail.com), May 15, 2002

Answers

I don't believe there is a method built into Tcl for doing this sort of thing.

Certainly Tcl's split command could be used to change your input string into a list. However, you would have to write code to change 5/1-4 into 5/1 5/2 5/3 5/4 . I would assume you would do some sort of parse via regular expression or scan to get the pieces you seek, then write a loop to get the rest. Perhaps something like this pseudo-Tcl code (in other words, this code probably won't work as I write it - it is intended to point you to a method):

set input "fa5/1-4,fa3/4-7,e4/23,e3/3-5" set l [split $input ,] foreach i $l { set lead "" set first "" set last "" set rc [scan $i "fa%d/%d-%d" lead first last] if {$rc != 3} { set rc [scan $i "fa%d/%d" lead first] set last $first } set output "" for {set j $first} {$j <= $last} {incr j} { set output [list $output $lead/$j] }

and output should be what you are seeking...

-- Larry W. Virden (lvirden@cas.org), June 17, 2002.


Moderation questions? read the FAQ