String and list of strings concatenation
From: Roger J. Meier (r_at_tac.ch)
Date: 10/31/03
- Next message: bitCrypT: "Re: entry widgets and tabbing"
- Previous message: Cameron Laird: "Re: Feasibility question: Simulating (basic) hardware ?"
- Next in thread: Ramon Ribó: "Re: String and list of strings concatenation"
- Reply: Ramon Ribó: "Re: String and list of strings concatenation"
- Reply: Glenn Jackman: "Re: String and list of strings concatenation"
- Reply: Don Porter: "Re: String and list of strings concatenation"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 31 Oct 2003 16:34:01 +0100
A procedure with the following signature
proc setMessage {msg args}
should consider "msg" as a string and "args" as a list of
strings with arbitrary content, including curly braces ({,
}), newline sequences (\r, \n) and double quotes (").
The goal is to return a string consisting of lines of text
which are separated by newline.
e. g.
setMessage a b c
gives
a
b
c
setMessage a\nb b c
gives
a
b
b
c
setMessage a\nb
gives
a
b
I came up with the following solution:
proc setMessage {msg args} {
if {[llength $args]} {
set all [join [eval list [list $msg] $args] "\n"]
} else {
set all $msg
}
return $all
}
It works with arbitrary and complex strings, even containing
braces and such. But... just to know: Is there a simple or
more elegant way to join "all"? It's not really important,
but I'm just wondering if I hit a good solution...
-- Roger
- Next message: bitCrypT: "Re: entry widgets and tabbing"
- Previous message: Cameron Laird: "Re: Feasibility question: Simulating (basic) hardware ?"
- Next in thread: Ramon Ribó: "Re: String and list of strings concatenation"
- Reply: Ramon Ribó: "Re: String and list of strings concatenation"
- Reply: Glenn Jackman: "Re: String and list of strings concatenation"
- Reply: Don Porter: "Re: String and list of strings concatenation"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]