splitting a $var in half

Help for those learning Tcl or writing their own scripts.
Post Reply
User avatar
NewzNZ
Halfop
Posts: 71
Joined: Thu Mar 05, 2009 5:15 am
Contact:

splitting a $var in half

Post by NewzNZ »

Hi - have searched the forum, but can't quite find what I need.

Just wanting to split a $var in half and insert another character in the middle.

eg. make: $abcdef into: $abc-def

The $var is always 6 characters long, and the split I want to make is always in the middle 3 and 3.

Thanks for any help!
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

Post by SpiKe^^ »

Try this...

Code: Select all

set var "[string range $var 0 2]-[string range $var 3 5]"
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
User avatar
NewzNZ
Halfop
Posts: 71
Joined: Thu Mar 05, 2009 5:15 am
Contact:

Post by NewzNZ »

That works beautifully...thanks SpiKe^^!
Post Reply