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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting ride of list brackets

Status
Not open for further replies.

rhull

Programmer
May 23, 2001
46
US

Is there a good way of removing the list lappend brackets that show up?

I have tried

set tran_date [string trim $tran_date ?/{]
set tran_date [string trim $tran_date ?/}]

but it does nothing!
Any ideas would be helpful.

Thanks!
-R
 
I suppose the real question is why do you want to do that? Presumably, you're using lappend because you want to build a well-formed Tcl list. lappend automatically quotes elements as needed to maintain valid list structure. But the quotes are not part of the element value, and are automatically "stripped" when you retrieve the element value. For example:

[tt]% lappend states California "New York" "North Dakota"
California {New York} {North Dakota}
% llength $states
3
% puts "The second state is [ignore][lindex $states 1][/ignore]"
The second state is New York[/tt]

Looking at your two lines of example code, I'm wondering if what you're really trying to do is simple string concatenation. In that case, you should be using the append command instead of lappend. let's take a look at a comparison:

Code:
% append test1 "The current time is "
The current time is
% append test1 [clock format   [clock seconds] -format "%I:%M:%S %p"]
The current time is 11:20:51 AM
% lappend test2 "The current time is "
{The current time is }
% lappend test2 [clock format   [clock seconds] -format "%I:%M:%S %p"]
{The current time is } {11:21:21 AM}
- Ken Jones, President
Avia Training and Consulting
866-TCL-HELP (866-825-4357) US Toll free
415-643-8692 Voice
415-643-8697 Fax
 
I had never seen just append used with a list so that was helpful. The brackets showed up when I took the data from the list and put in into a database, they just stayed with the element. So is there any benefit to using lappend over append?

-R
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top