Re: [Activetcl] split doing two different things
by Flavio Salgueiro other posts by this author
Apr 7 2008 9:14PM messages near this date
view in the new Beta List Site
Re: [Activetcl] split doing two different things
|
Re: [Activetcl] split doing two different things
I think that the extra field he is seeing is due to the normal behavior of split. The traili
ng Ã? at the end of the list will give you an empty string.
My suggestion is to use 'string trim $myString Ã?' to get rid of the trailing delimiter whic
h is giving the extra blank field at the end. You would get the same result if you tried 'll
ength [split a: :]' this would result in a count of two because split gives you "a and {}" n
ot just "a".
Cheers,
Flavio
@-> -----Original Message-----
@-> From: activetcl-bounces@[...].com [mailto:activetcl-
@-> bounces@[...].com] On Behalf Of Jeff Hobbs
@-> Sent: Monday, April 07, 2008 6:10 PM
@-> To: Gene Osteen
@-> Cc: activetcl@[...].com
@-> Subject: Re: [Activetcl] split doing two different things
@->
@-> Gene Osteen wrote:
@-> > I use the split command to tell me how many fields are in
@-> a
@-> > line of text sent to me. The data is character delimited with a Ã? as
@-> the
@-> > delimiter. Each line of text ends with a Ã?. Normally if I do a split I
@-> > get one more list element than there are fields. I have a case where
@-> > this is not happening. I am including 2 examples. The first is not
@-> > working as expected the line of data is:
@-> >
@-> > 314185798Ã?59858Ã?2004-11-19Ã?2004-11-19 23:08:00Ã? KPFS-IN
@-> > NCAL-INTERFACEÃ?121314Ã?121314Ã?121314Ã?
@-> >
@-> > For some reason the list length here is 8 which is also the number of
@-> Ã?s
@-> > in the line.
@->
@-> I don't have the same issue, getting the expected correct results with
@-> 8.4.18 and 8.5.2:
@->
@-> (Tcl) 49 % set str {314185798Ã?59858Ã?2004-11-19Ã?2004-11-19 23:08:00Ã?
@-> KPFS-IN NCAL-INTERFACEÃ?121314Ã?121314Ã?121314Ã?}
@-> 314185798Ã?59858Ã?2004-11-19Ã?2004-11-19 23:08:00Ã? KPFS-IN
@-> NCAL-INTERFACEÃ?121314Ã?121314Ã?121314Ã?
@-> (Tcl) 50 % regexp -all Ã? $str
@-> 8
@-> (Tcl) 51 % llength [split $str Ã?]
@-> 9
@-> (Tcl) 52 % split $str Ã?
@-> 314185798 59858 2004-11-19 {2004-11-19 23:08:00} { KPFS-IN
@-> NCAL-INTERFACE} 121314 121314 121314 {}
@->
@-> Jeff
@-> _______________________________________________
@-> ActiveTcl mailing list
@-> ActiveTcl@[...].com
@-> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
_______________________________________________
ActiveTcl mailing list
ActiveTcl@[...].com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Thread:
Gene Osteen
Jeff Hobbs
Flavio Salgueiro
Michael Bahr
Jeff Hobbs
Michael Bahr
Dossy Shiobara
Michael Bahr
Dossy Shiobara
Michael Bahr
Jeff Hobbs
Enrico Herzke
Michael Bahr
Jeff Dinsmore
Michael Bahr
Gene Osteen
Jeff Dinsmore
Enrico Herzke
|