使用 Tcl 在各个数据库记录前面连接文本

发布于 2024-08-27 15:09:22 字数 735 浏览 5 评论 0原文

简而言之,目前我正在使用以下代码从 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

童话里做英雄 2024-09-03 15:09:22

你说得对。 foreach 命令是执行此操作的正确方法。方法如下:

set SrchValsALL {}
foreach value [concat $SrchVals1 $SrchVals2 $SrchVals3] {
    lappend SrchValsALL "Sub: $value"
}
$SearchBar configure -value $SrchValsAll

You're right. The foreach command is the right way to do it. Here's how:

set SrchValsALL {}
foreach value [concat $SrchVals1 $SrchVals2 $SrchVals3] {
    lappend SrchValsALL "Sub: $value"
}
$SearchBar configure -value $SrchValsAll
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文