Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Split question

Status
Not open for further replies.

Jboy123

MIS
Jun 8, 2004
24
CH
Hi All

Aplogies in advance for a dumb question.

I'm trying to read in a file format as follows:

myVariableName=myValue

I then do a split against this:
set props [ split $arg = ]

Then I assign assign values to my variables:
set [lindex $props 0] [lindex $props 1]

That's all fine until my file contains something like:

myvariableName=myValue=1234

Of course the split discards the last value. I want to keep the value as "myValue=1234"

Is there a split option to tell it to split only on the first occurrence of the = ??

Or - a better way to fo this?

Many thanks in advance
Jules

 
Since you know that you only want to split what comes before and after the first "=" you could do something like this.

set props [ split $arg = ]
set first_element [lindex $props 0]
set second element [lrange $props 1 end]



The lrange command is useful in these situations. It allows you to grab multiple parts of the list at a time. Since you arent sure of where your last element is you may use "end".
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top