0

Inputting the following four lines into the IDL console gives the output below.

IDL> num=123
IDL> str="bananas"
IDL> join=str+string(num)
IDL> print,join
bananas     123

Why are 5 spaces appearing in the string and how can I stop it happening?

airdas
  • 872
  • 2
  • 11
  • 19

1 Answers1

1

Numerical values are padded with leading blank spaces when converted with the STRING function. Use STRTRIM instead. The argument "2" removes both leading and trailing whitespace.

IDL> num=123
IDL> str="bananas"
IDL> join=str+STRTRIM(num,2)
IDL> print,join
bananas123

The STRTRIM documentation explains more about the extra spaces. This page on formatted output also has details on whitespace padding.

Steve G
  • 182
  • 9