String map command

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf String map command

  • Creator
    Topic
  • #50659
    Michael Hertel
    Participant

      I am trying to do the following:

      set data [string map {x $newx} $data]

      I am getting literal “$newx” instead of the variable value.

      I’ve played around with escapes and brackets and give up.

    Viewing 4 reply threads
    • Author
      Replies
      • #67020

        Try it with eval. Might work.

        -- Max Drown (Infor)

      • #67021

        Nevermind the eval comment. Here’s how you do it:

        Code:

        set data “x”
        set newx “Hello, World!”
        set data [string map [list x $newx] $data]
        echo $data

        -- Max Drown (Infor)

      • #67022
        Michael Hertel
        Participant

          Thanks Max, I knew it was too easy.

        • #67023
          Charlie Bursell
          Participant

            Your origianal code did not work because the $ value was inside curly braces.  It was interpreted as literal $newx

            Had you done it like:  set data [string map “x $newx” $data]

            It would have worked as expected

          • #67024
            Michael Hertel
            Participant

              I thought I tried double quotes. Oh well.

              Also, I’m wondering where I came up with the curly braces in the first place. Seems to me that was the only way it would work once.

              Thanks for the info Charlie.

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