TCL 从列表中删除一个元素
如何从 TCL 列表中删除一个元素说:
- 其索引 = 4
- 其值 =“aa”
我已经用 Google 搜索过,但尚未找到任何内置函数。
How te remove an element from TCL list say:
- which has index = 4
- which has value = "aa"
I have Googled and have not found any built-in function yet.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
按索引删除
按值删除
Remove by index
Remove by value
删除元素的另一种方法是将其过滤掉。此 Tcl 8.5 技术与其他地方提到的
lsearch
&lreplace
方法不同,因为它从列表中删除给定元素的全部。它不做的是搜索嵌套列表。这是 Tcl 没有花精力太深入地理解数据结构的结果。 (不过,您可以通过
-index
选项告诉它通过比较子列表的特定元素来进行搜索。)The other way to remove an element is to filter it out. This Tcl 8.5 technique differs from the
lsearch
&lreplace
method mentioned elsewhere in that it removes all of a given element from the list.What it doesn't do is search through nested lists. That's a consequence of Tcl not putting effort into understanding your data structures too deeply. (You can tell it to search by comparing specific elements of the sublists though, via the
-index
option.)假设您想要替换元素“b”:
您可以将第一个元素 1 和最后一个元素 1 替换为空:
Lets say you want to replace element "b":
You replace the first element 1 and last element 1 by nothing:
regsub
也可能适合从列表中删除值。regsub
may also be suitable to remove a value from a list.刚刚完成了别人所做的事情
然后打电话
Just wrapped up what others have done
Then call with
你也可以这样尝试:
You can also try like this :
有两种简单的方法。
There are 2 easy ways.