Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Splitting on multiple character token

0 views
Skip to first unread message

Jete Software Inc.

unread,
Jan 23, 1996, 3:00:00 AM1/23/96
to
I always make my delimiters multiple number of characters because I
always eventually get burned on my chosen character (still do just
takes much longer). But split seems to want to only split on a
single character. Why??

% 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

Thomas Martin

unread,
Jan 24, 1996, 3:00:00 AM1/24/96
to

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 |
| | |
+----------------------------------------+------------------------------------+

Michael Salmon

unread,
Jan 25, 1996, 3:00:00 AM1/25/96
to
Jete Software Inc. wrote:
>
> I always make my delimiters multiple number of characters because I
> always eventually get burned on my chosen character (still do just
> takes much longer). But split seems to want to only split on a
> single character. Why??
>
> % 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???

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.

0 new messages