I am trying to append spaces on a line because it is a fixed length

Clovertech Forums Cloverleaf I am trying to append spaces on a line because it is a fixed length

  • Creator
    Topic
  • #119338
    Tom Gilbert
    Participant

      The problem is the source does not fill in after it gives me the last field so I am using tcl to fill that in so I can use it as fixed when I do the mapping. I tried concat but from what I read it automatically removes leading and trailing spaces. How can I do this without losing the space buffering.

    Viewing 5 reply threads
    • Author
      Replies
      • #119339
        Gene Millard
        Participant

          We use this to do that.
          while {[string length $line] < 4} {
          append line “”
          }

          • This reply was modified 3 years, 1 month ago by Gene Millard.

          The Guthrie Clinic
          Sayre, PA

        • #119341
          Gene Millard
          Participant

            That should be a ” ” instead of “”

            The Guthrie Clinic
            Sayre, PA

          • #119342
            Gene Millard
            Participant

              you might have to set a variable to ” ” to get it to work
              set x ” ”

              append line $x

              The Guthrie Clinic
              Sayre, PA

            • #119343
              Tom Gilbert
              Participant

                Hello All, looks like I got it. Here is what I am using:

                set newspccntn1p5 [append test $seg$spccntn1p5]

                Why do we have to put ‘test’ in for a variable? Does not affect the outcome, I am just curious.

                Thank you…

              • #119344
                David Barr
                Participant

                  I think your code is relying on the fact that append returns the new value of test as well as modifying the variable. A simpler way is “set newspccntn1p5 $seg$spccntn1p5”.

                • #119345
                  David Barr
                  Participant

                    I would probably do something like this:

                    set newspccntn1p5 [format “%-12s” $seg]

                    This would format seg as a 12 character string (adding necessary spaces on the right) and store the result in newspccntn1p5.

                Viewing 5 reply threads
                • You must be logged in to reply to this topic.