使用以分号结尾的单词的列表? [英] Working with lists that have words ending in semi-colons?

查看:23
本文介绍了使用以分号结尾的单词的列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以将以分号结尾的字符串(单词)添加到列表中,而列表本身又不是单项列表?

Is there a way to add strings (words) that end with a semi-colon to a list without it being a single-item list itself?

我正在处理字符串并将它们分解成单词;并且标点符号通常作为后缀附加.我需要同时使用两个词,即带标点和不带标点.

I'm working with strings and breaking them into words; and the punctuation often is attached as a suffix. I need to have the words both ways, that is with and without the punctuation.

是否可以简单地让它成为列表中的列表,并像引用单项列表一样引用所有单词?它似乎有效.或者有没有更好的方法?

Is it okay to simply let it a be a list within a list, and just reference all of the words as if they were single-item lists? It appears to work. Or is there a better method altogether?

谢谢.

set list { a; b c d }
chan puts stdout $list; # a; b c d

set new "b;"
lset list 1 $new

chan puts stdout $list; # {a;} {b;} c d
chan puts stdout [lindex [lindex $list 1] 0]; # b;
chan puts stdout [lindex [lindex $list 3] 0]; # d
chan puts stdout [lindex $new 0]; # b;

推荐答案

我正在处理字符串并将它们分解成单词

I'm working with strings and breaking them into words

在此步骤中使用 split 很重要,除此之外,您应该可以通过附加到如此生成的列表来使用它.各种列表命令将确保特殊字符(您的 ;)不会被错误解释.

It is important to use split for this step, other than that, you should be fine using the so-produced list by appending to it. The various list commands will make sure that special characters (your ;) will be protected from being ill-interpreted.

从 Tcl 的角度来看,单元素列表 {a;} 和原子字符串 a; 之间没有区别.引用Tclers' Wiki:

From the Tcl perspective, there is no difference between a single-element list {a;} and an atomic string a;. To quote the Tclers' Wiki:

没有程序可以分辨字符串a"和a"之间的区别.和单元素列表a",因为单元素列表a"是字符串一个".

No program can tell the difference between the string "a" and the one-element list "a", because the one-element list "a" is the string "a".

不要让花括号迷惑你.

这篇关于使用以分号结尾的单词的列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆