tcl - 在 Tcl 中用换行符连接字符串

标签 tcl

我无法在 tcl 中连接具有新行的字符串。新行将被忽略。有办法克服这个问题吗?

% set pst_data "Power states :-\n"
Power states :-

% set pst_data [concat $pst_data "vcc1\t 1 0 1\n"]
Power states :- vcc1     1 0 1
% set pst_data [concat $pst_data "vcc2\t 2 2 0\n"]
Power states :- vcc1     1 0 1 vcc2      2 2 0
% 

我希望输出每次都以单独的新行出现

最佳答案

它在 manual 中提到了它:

This command joins each of its arguments together with spaces after trimming leading and trailing white-space from each of them.

您可以尝试使用 append相反:

% set pst_data "Power states :-\n"
Power states :-

% append pst_data "vcc1\t 1 0 1\n"
Power states :-
vcc1     1 0 1

% append pst_data "vcc1\t 1 0 1\n"
Power states :-
vcc1     1 0 1
vcc1     1 0 1

%

关于tcl - 在 Tcl 中用换行符连接字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65948651/

相关文章:

debugging - 调试期望脚本时出现“段错误”

python - python 2.5 是否具有与 Tcl 的 uplevel 命令等效的功能?

https - 使用 TCL 请求 HTTPS 时出现问题

tcl - 错误 : unknown option "-state" occurs when running a script named button.

regex - 当表达式具有 [0] 时,TCL regsub 不工作

tcl - 我们可以在 tclOO 中定义静态函数吗?

list - 如何在 tcl 中比较两个列表(其中包含字符和数字)?

c++ - QProcess 多平台命令

foreach - 打破tcl中超过1层的foreach嵌套

tcl - 如何在 tcl switch 语句中使用 或 ?