Replace HL7 escape sequence .sk+n with n spaces

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf Replace HL7 escape sequence .sk+n with n spaces

  • Creator
    Topic
  • #53625
    Robert Kersemakers
    Participant

      Hi all,

      I need to translate an HL7 ORU into an EDIFact message. The ORU message contains a textual result, with lots of .sk+4 or .sk+49 escape sequences. So I want to replace these .sk+n escape sequences with n spaces.

      I want to this with a regsub. I’m not very fluent in regexp/regsub, but got pretty far: I can isolate the number n, but I can’t get the regsub to put in n spaces. Let me show you:

      Code:

      hcitcl>set a “test\.sk+5\regel”
      test.sk+5regel
      hcitcl>regsub -all — {\.sk+(d)\} $a {A1} b
      1
      hcitcl>echo $b
      testA5regel
      hcitcl>regsub -all — {\.sk+(d)\} $a [string repeat “A” 1] b
      Error: expected integer but got “”
      hcitcl>regsub -all — {\.sk+(d)\} $a [string repeat “A” \1] b
      Error: expected integer but got “1”

      In the end I have tried loads of combinations to get the 1 to work inside the ‘string repeat’ but no luck. Has anybody done something like this before? Or knows how to do this?

      If I can’t get it to work with one regsub, I will use the regsub to replace .sk+n with something like ~n and then write some tcl code to replace all ~n with n spaces.

      Thanks!

      Zuyderland Medisch Centrum; Heerlen/Sittard; The Netherlands

    Viewing 2 reply threads
    • Author
      Replies
      • #78332
        Charlie LaBaw
        Participant

          regexp — {\.sk+(d)\} $a b1 b2

          regsub -all — {\.sk+(d)\} $a [string repeat “A” $b2] c

        • #78333
          Charlie Bursell
          Participant

            That would find only the fisrts instance

            I haven’t tested it but how about

            foreach {full spaces} [regexp -all -inline — {B.sk+(d)B} $a] {

                   

                         set a [string map

              ] $a]

              }

            1. #78334
              Robert Kersemakers
              Participant

                Hi Charlie/Charles,

                Thanks to the both of you: I got both your solutions to work by combining them.

                You can do either

                Code:

                while {[regexp — {\.sk+(d+)\} $tekst full spaces]} {
                 regsub — {\.sk+(d+)\} $tekst [string repeat ” ” $spaces] tekst
                }


                or

                Code:

                foreach {full spaces} [regexp -all -inline — {B.sk+(d+)B} $tekst] {
                 regsub — {\.sk+(d+)\} $tekst [string repeat ” ” $spaces] tekst
                }

                I also tried to use the $full in the regsub instead of {\.sk+(d+)\}, but I didn’t get that to work. This works great though!

                Zuyderland Medisch Centrum; Heerlen/Sittard; The Netherlands

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