dictionary - 如何将 TCL 字典形成为字符串以将其作为字符串变量传递?
问题描述
我需要格式化一个可以解释为 TCL 字典的字符串。基本上,字符串是用 C++ 形成的,然后作为字符串变量值传递给 TCL 解释器,TCL 解释器应该能够将该字符串值视为字典。这可能吗,如果可以,应该如何格式化该字符串?
解决方案
任何具有偶数个单词(由 tcl 定义)的字符串都是字典。
示例tclsh
会话:
% set demo "a silly example string"
a silly example string
% dict get $demo a
silly
% dict get $demo example
string
如果您有多个单词的键或元素,则应将它们括在大括号中:
% set example "a {multi word value} {multi word key} test"
a {multi word value} {multi word key} test
% dict get $example a
multi word value
% dict get $example "multi word key"
test
推荐阅读
- python-3.x - 范围不工作的for循环内的返回语句
- php - 不要从数组中删除重复值
- android - 如何在导航抽屉中打开具有来自动态数组的动态菜单列表的片段
- c# - 如何使用威布尔分布中的随机数?
- angular - ngx-mydatepicker - 日历的位置未与输入对齐
- symfony - 如何使用奏鸣曲管理员创建具有固定装置的用户
- c# - 自动创建 RectTransform 的原因
- javascript - 在 React 中选择/取消选择自定义表中的行
- javascript - 如何在节点 js 中使用 oracle 高级队列(OAQ)
- php - 尽管“全局”,php在函数中没有变量