REGSUB & question. Not working as expected.

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf REGSUB & question. Not working as expected.

  • Creator
    Topic
  • #54416
    Mike Wilson
    Participant

      I am having some issues replacing characters.  Any ideas?

      Here is the regsub:  it works as expected for the &.  But the single quote, doubl, GT and LT are all appending the character as opposed to replacing it.  

      set xmlMsg [regsub -all {&} $xmlMsg “&”]

      set xmlMsg [regsub -all {“} $xmlMsg “"”]

      set xmlMsg [regsub -all {‘} $xmlMsg “'”]

      set xmlMsg [regsub -all {<} $xmlMsg "<"] set xmlMsg [regsub -all {>} $xmlMsg “>”]

      Here is the Original Segment:

      REMOVE|’|”|&|>|<| Here is the output of the regsub: REMOVE|’apos;|quot;|&|>gt;|

    Viewing 1 reply thread
    • Author
      Replies
      • #81376
        Mike Wilson
        Participant

          Not sure why the & was working to store the original replaced character but I fixed it by adding \ in front of the &.  like so “\"”  not sure of the reasoning.

        • #81377
          Charlie Bursell
          Participant

            That is because you are dealing with meta characters here which require special handling.  Why do that when string map is much better unless you need to do a partial replace of deliniate the replacement somehow.  The ; is still special to Tcl as it ends a command.

            # Do & separate so as not to screw up other changes

            # Put ; and others inside braces so Tcl will not interpret

            set xmlMsg [string map

              $xmlMsg]

              # List of other replacements

              set map

              # Do the rest

              set xmlMsg [string map $map $xmlMsg]

        Viewing 1 reply thread
        • The forum ‘Cloverleaf’ is closed to new topics and replies.