% set str "first:#:second:#:third"
first:#:second:#:third
% set me [split $str :#:]
first {} {} second {} {} third
% llength $me
7
I want the answer "3". So how do I get it???
-- Norman
It seems, that split has problems with multicharacter delimiters, so
I propose following solution to solve this problem:
set str "first:#:second:#:third"
if [info exists me2] {unset me2}
foreach i [split $str ":#:"] {
if {$i!=""} {lappend me2 $i}
}
puts [llength $me2]
==> 3
+-----------------------------------------------------------------------------+
| |
| Thomas Martin, Informatiker Abteilung EM (EM Dept.) |
| |
+----------------------------------------+------------------------------------+
| | |
| | H.Stoll GmbH & Co. |
| @@ @@ @ | Stollweg 1 |
| @@ @@ @ ___ _____ ___ | W-7410 Reutlingen |
| @@ @@ @ <___` | | | | | | Germany |
| @@ @@ @ ___> | \___/ |___ |___ | Tel.: +49 (0)7121/313-346 |
| @@ @@ @ | Fax.: +49 (0)7121/313-372 |
| | e-mail: thom...@stoll.de |
| | |
+----------------------------------------+------------------------------------+
I think that you have misread the man page for split, as I read it split
separates the source string when it finds any of the characters in the
separator string. Your results are consistant with my interpretation. If
you want to break on multiple characters then regexp is probably better.
--
© 1995 Michael Salmon
All opinions expressed in this article remain the property of
Michael Salmon. Permission is hereby granted for use in
followup articles, FAQ's and digests.