How can i replace *~r with just a newline

Homepage Clovertech Forums Read Only Archives Cloverleaf Cloverleaf How can i replace *~r with just a newline

  • Creator
    Topic
  • #49980
    Rick Pritchett
    Participant

    here is my code so far.

               keylget args MSGID mh

               set msg [msgget $mh]

               regsub -all {~r} $msg {n} msg

               msgset $mh $msg

               lappend dispList “CONTINUE $mh”

Viewing 7 reply threads
  • Author
    Replies
    • #64376
      Tom Rioux
      Participant

      I’m assuming the “*” is simply a wildcard and that all you are wanting to replace is the “~r”.  If that is the case, try this:

      regsub -all ~\r $a \n b

      Not sure if this is exactly what you want.

      hcitcl>set a ~r

      hcitcl>regsub -all ~\r $a \n b

      1

      hcitcl>echo $b

      n

      Let me know if this works for you.

      Tom Rioux

      Baylor Health Care System

    • #64377
      Charlie Bursell
      Participant

      C’mon guys, don’t make this harder than it should be.  For simple find/replace always us a string map and don’t worry about what needs to be escaped.

      string map “~r n” $var

    • #64378
      Kevin Kinnell
      Participant

      Rickey Pritchett wrote:

      here is my code so far.

        …

                 regsub -all {~r} $msg {n} msg

        …

      Are you sure that’s what you want?  I can see replacing all of the characters with characters if you just want to look at the data, but it doesn’t look to me like that’s what you’re doing.

      Newline terminated messages end segments with “r” and entire messages with “rn”.

      Okay, with that out of the way…

      You’re running afoul of the Tcl quoting and the regsub command interpretation rules.   Generally, {sr} will get you the a string of the literal characters ‘s’ ” ‘r’ if there is only one round of interpretation,  but it gets you ‘s’ and a newline if there is another round.  The regsub command needs the regular expression string uninterpreted, so this is good for sending it the regex.  It quite unfairly doesn’t interpret the replacement string, however.  The easy way to get around this is to quote an escaped character with interpolation quotes — e.g. “r”, if you want to get a .

      So

      Code:

      regsub -all {~r} $msg “n” msg


      will probably do what you are trying to do, but are you sure that’s what you want?

    • #64379
      Kevin Kinnell
      Participant

      Charlie Bursell wrote:

      C’mon guys, don’t make this harder than it should be.

      Jeez, Charlie!  The Principle of Least Confusion doesn’t apply to forum questions–you’re supposed to guess what’s really being asked!

      Quote:

      Merchant: No, no, no — you’re supposed to haggle!

        “Ten for that? you must be mad!”

        You know, HAGGLE!

      Brian(desperate): But I don’t care how much it is; I’ll pay whatever you like!

      Merchant: Oh dear oh dear oh dear…

      –kevin (I can always find a way to be a condescending jerk by not reading everything in a post 😳 ) kinnell

    • #64380
      Rick Pritchett
      Participant

      i get this error now

      char map list unbalanced

         while executing

      “string map “~r n” $msg”

         (“run” arm line 8)

      using this code

       set msg [string map “~r n” $msg]

    • #64381
      Kevin Kinnell
      Participant

      Charlie got burned by quoting too… It’s expecting a list.  Try

      Code:

      string map {~r n} $msg

      –kevin (I feel slightly less embarassed now) kinnell

    • #64382
      Charlie Bursell
      Participant

      Somebody has to keep me straight  ðŸ˜€

      I did this from my hotel and didn’t have a chance to test it

    • #64383
      John Hamilton
      Participant

      I am pretty sure it will take more then one person to keep you stright Charlie.  ðŸ˜¯

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

Forum Statistics

Registered Users
5,117
Forums
28
Topics
9,292
Replies
34,435
Topic Tags
286
Empty Topic Tags
10