使用 Tcl 在各个数据库记录前面连接文本
简而言之,目前我正在使用以下代码从 Sqlite Db 中的多个表中提取记录并将它们插入到单个组合框($SearchBar)中:
set SrchVals1 [db eval {SELECT DISTINCT Stitle From Subcontract Order By Stitle ASC}]
set SrchVals2 [db eval {...
set SrchVals3 ...
set SrchValsALL [concat $SrchVals1 $SrchVals2 $SrchVals3]
$SearchBar configure -value $SrchValsAll
对于变量“SrchVals1”,我正在尝试找出一种方法来连接将“Sub:”文本发送到SrchVals1 中的每个单独记录。例如,如果 SrchVals1 在组合框中显示以下记录:
First Title
Second Title
Third Title
我想连接,以便组合框中的记录如下所示:
Sub: First Title
Sub: Second Title
Sub: Third Title
我知道我可能必须使用 foreach 语句;然而,我没有运气写一个在每条记录前面添加“Sub:”的记录,而不是一条记录。这看起来应该很容易,但我似乎无法弄清楚。
有谁知道我怎样才能达到这些结果?
谢谢你,
东风公司
In short, currently I am using the following code to pull records from multiple tables in a Sqlite Db and insert them in a single combobox ($SearchBar):
set SrchVals1 [db eval {SELECT DISTINCT Stitle From Subcontract Order By Stitle ASC}]
set SrchVals2 [db eval {...
set SrchVals3 ...
set SrchValsALL [concat $SrchVals1 $SrchVals2 $SrchVals3]
$SearchBar configure -value $SrchValsAll
For the variable "SrchVals1", I am trying to figure out a way to concatenate the text "Sub: " to each individual record in SrchVals1. For example, if SrchVals1 shows the following records in the combobox:
First Title
Second Title
Third Title
I would like to concatenate so that the records in the combobox look like this:
Sub: First Title
Sub: Second Title
Sub: Third Title
I understand that I might have to use a foreach statement; however, I am having no luck writing one that adds "Sub: " in front of each record, as opposed to one. This seems like something that should be pretty easy, but I cannot seem to figure it out.
Does anyone know how I can achieve these results?
Thank you,
DFM
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你说得对。
foreach
命令是执行此操作的正确方法。方法如下:You're right. The
foreach
command is the right way to do it. Here's how: