Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
416 views
in Technique[技术] by (71.8m points)

Concatenating strings with newlines in Tcl

I am unable to concatenate strings having new lines in tcl. The new lines are ignored. Is there a way to overcome this?

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

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

I want the output to come in separate new lines every time

question from:https://stackoverflow.com/questions/65948651/concatenating-strings-with-newlines-in-tcl

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

It mentions it in the manual:

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

You could try using append instead:

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

% append pst_data "vcc1 1 0 1
"
Power states :-
vcc1     1 0 1

% append pst_data "vcc1 1 0 1
"
Power states :-
vcc1     1 0 1
vcc1     1 0 1

%

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...