[英]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.