czchlong
czchlong

Reputation: 2594

Tcl split by tabs (\t)

I am trying to split a Tcl string by TABS (\t).

Please consider the following sampleString:

I . am -> a . programmer # let "." be spaces and "->" be tabs

If I try to do the following:

set myVar [split $sampleString "\t"]

Tcl will split by spaces as well and not just the tabs.

How can I split only by tabs?

Thanks

Upvotes: 0

Views: 5732

Answers (1)

Donal Fellows
Donal Fellows

Reputation: 137757

I suspect you're just a little confused as to which output you are looking at.

% set s "I am\ta programmer"
I am    a programmer
% split $s
I am a programmer
% split $s "\t"
{I am} {a programmer}

The only difference between the two splits is that without the optional second argument, the split-set is “all whitespace” (for a reasonable definition of “all”), and neither split affects the value in the variable as there is no explicit write-back here.

Upvotes: 4

Related Questions