Reputation: 1
I have a hierarchy string
Aa/bb/cc/dd
Ff/gg/hh/ii
I can get length but don't know how to get the index of last "/" How to get the output one hierarchy above?
Aa/bb/cc
Ff/gg/hh
Upvotes: 0
Views: 126
Reputation: 137557
To get rid of the last component like that, use one of:
regsub {/[^/]+$} $input ""
— not for filenames!join [lrange [split $input "/"] 0 end-1] "/"
— not for filenames!file dirname $input
— for filenamesThat has to be lifted to work over a list of values. The lmap
command is convenient for that; for example:
set outputList [lmap value $inputList {file dirname $value}]
Upvotes: 1