user1270123
user1270123

Reputation: 573

How to concatenate strings in TCL without adding whitespace

I want to concatenate two strings without any whitespaces between the strings that are being concatenated. But when I use the commands below, I get strings concatenated with whitespaces added between them. How to concatenate the strings without adding whitespaces?

set A "Test"
set B "data"

set C $A$B

Current Output :

Test       data

I need output similar to this :

Testdata

Upvotes: 3

Views: 17288

Answers (3)

Deeraj Reddy
Deeraj Reddy

Reputation: 46

Try using append command

syntax for append is

append var "," $value 
                        #appends value to variable

Without specifying the quotes, the default is null

so,

  set A "Test"
  set B "data"
  append A $B
  puts "$A"

The variable contains "Testdata"

Upvotes: 1

Francis Pang
Francis Pang

Reputation: 81

You can use the Tcl command join.

% set A "Test"
Test
% set B "data"
data
% join [list $A $B] ""
Testdata

Upvotes: 1

sti
sti

Reputation: 11075

If I try that, it works like this:

$ tclsh
% set A "Test"
Test
% set B "data"
data
% set C $A$B
Testdata

Could it be you have accidentally entered some control character between A and $?

Upvotes: 8

Related Questions