Tcl lreplace 无法替换大括号?
这个代码示例应该做什么?
set l { A B C D }
lreplace $l 1 2 \[ \]
它返回 {A {[} \] D}
,但是我想要 {A [ ] D}
。
我做错了什么?
What should do this code sample?
set l { A B C D }
lreplace $l 1 2 \[ \]
It returns {A {[} \] D}
, however I want to have {A [ ] D}
.
What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的代码完全按照您想要的方式执行,您只是读取输出的字符串代表并误解它:
当您读取字符串代表时,您会看到它转义了 [ 和 ]。正如您从 foreach 输出中看到的,实际值就是您所要求的。如果您想要的只是包含相关字符的字符串,则可以使用
join
获取您感兴趣的字符串。Your code does exactly what you want it to, you're just reading the string rep of your output and misunderstanding it:
When you read the string rep, you're seeing it escape the [ and ]. As you can see from the foreach output, the actual values are what you're asking for. You can use
join
to get the string you're interested in if what you want is just a string with the characters in question.