簡體   English   中英

Tcl字符串操作和替換

[英]Tcl String Manipulation and Substitution

set i 0
set student$i tom

(當然,這等效於set student0 tom

我想獲取student0的值,即字符串“ tom”。 如果必須在這里使用$i表示0該如何獲取? 我嘗試了$(student$i)$"student$i"和許多其他方式,但是無法獲取字符串“ tom”。 (我不$student0這里那樣硬編碼$student0 )。

有什么辦法解決這個問題? 謝謝!

您可以使用set命令-它返回變量的值:

puts "the student is [set student$i]"

但是,這種事情通常比其價值更大。 使用數組,以i作為數組的索引:

set student($i) tom
puts "the student is $student($i)"

1]設定i 0

設置學生$ i為“ tom”

放置[替換$ [替換學生[替換$ i]]]

2]使用數組

設置我0

設置學生($ i)“ tom”

把$ student($ i)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM