user3126850
user3126850

Reputation: 13

Parsing string and getting value in TCL

I've string like this a sample one what I need is parse through the string and get the value of a parameter for example value of -type is Eth, so just the string next to the string I give.

card-1-3-1 3 -Number 2 -type Eth -config Yes -GEPorts 3

Upvotes: 1

Views: 244

Answers (1)

Peter Lewerin
Peter Lewerin

Reputation: 13252

set s {card-1-3-1 3 -Number 2 -type Eth -config Yes -GEPorts 3}
dict get $s -type
# -> Eth

By default, card-1-3-1 becomes a key in the "eyes" of the dict command, but as long as that isn't a problem you don't need anything more complex than this. All the keys must have following values (i.e. the string must be a proper, even-sized list where the items are in key-value order).

Documentation: dict, set

Upvotes: 2

Related Questions