escape the ampersand "&" in tcl

Clovertech Forums Read Only Archives Cloverleaf Tcl Library escape the ampersand "&" in tcl

  • Creator
    Topic
  • #51637
    Thomas Fortino
    Participant

      AIX 5.2

      Version 5.3P Rev2

      Hello All,

      I’m trying to change all special characters in an XLTP proc to space and the & to the word and. I can get all the characters changed except the ampersand.

      below is my code can anyone comment on what I’m going wrong. When I echo the input I only get what is to the right of the ampersand. If there is no ampersand in the field I get the full field value.

      There are no syntax errors and I get the correct output if there isn’t an ampersand.

      regsub -all — & [lindex $xlateInVals 0] “and” noampers;

      echo $noampers

      set char $noampers

      regsub -all — {,|.|-|(|)|/} $char { } char1;

      set xlateOutVals

        }

    Viewing 2 reply threads
    • Author
      Replies
      • #71065
        Charlie Bursell
        Participant

          I tied it and it woks for me

          set xlateInVals

            regsub -all — & [lindex $xlateInVals 0] “and” noampers

            echo $noampers

                ==>  Now and Then

            Why are you putting semicolon at th eend of all statements?  This is not Java or Perl  ðŸ˜€

            If I were doing this I would rather use string map anyway and no escaping is required

            set noampers [string map

            [lindex $xlateInVals 0]]
        • #71066
          Jim Kosloskey
          Participant

            Tom,

            It has been a while since I played with this but I seem to recall the issue is when you reference the field in which the ampersand exists, the Xlate sees the ampersand and stops populating your xlateInVals at that point.

            So for example if your field (or component for that matter) is |this&that|

            what you would see if you echoed out lindex xlateInVals 0 is this not this&that.

            So your proc really does not see the ampersand.

            This is of course assuming the issue is that the ampersand is your sub-component separator defined in MSH-2

            email: jim.kosloskey@jim-kosloskey.com 29+ years Cloverleaf, 59 years IT - old fart.

          • #71067
            Gary Atkinson
            Participant

              What have done before is do this in a pre-detail and post detail proc.  I change the & to T and in the post proc, do the reverse.

          Viewing 2 reply threads
          • The forum ‘Tcl Library’ is closed to new topics and replies.