TCL split ??

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf TCL split ??

  • Creator
    Topic
  • #49225
    Chad Ward
    Participant

      I need to split the obx.5 when I have a MIC sensitivity, so that I can take

      Gentamicin, <=1, S and put them into seperate fields.  The spacing from the rec. system is not allows consistent.   OBX|23|ST|CUL SS^Culture, Routine||    Gentamicin                            <=1  S||| Thanks, Chad

    Viewing 3 reply threads
    • Author
      Replies
      • #61156
        Greg Eriksen
        Participant

          Hi Chad,

          I’m no expert at tcl, but since no one else has replied yet I thought I’d give it a shot.  There is probably a better way, but the following might give you some ideas:

          hcitcl>set data ”    Gentamicen         <=1 S" hcitcl>set list1 [split $data]

          hcitcl>echo $list1

          {} {} {} {} Gentamicen {} {} {} {} {} {} {} {} <=1 S hcitcl>foreach element $list1 {

          =>if {![lempty $element]} {lappend list2 $element}

          =>}

          hcitcl>echo $list2

          Gentamicen <=1 S hcitcl>set field1 [lindex $list2 0]

          hcitcl>echo $field1

          Gentamicen

          The problem I see with this approach is if the drug name is two or more words containing embedded spaces.

        • #61157
          Charlie Bursell
          Participant

            If you were sure there would always be 3 subfileds, you already have a list. Remember a list is strings separated by white space.  Therefore if

             data = ”    Gentamicen         <=1 S" Then lassign $data a b c echo ($a) => (Gentamicen)

            echo ($b)

            => (<=1) echo ($c) => (5)

            This would be true regardless of how many spaces there were between each.

            However, as Greg said, if you have a drug with more than one string in it’s name, all bets are off.

            It might be better to better describe just what you want to do.

          • #61158
            Steve Carter
            Participant

              Try this:

              hcitcl>set source ”    Gentamicen         <=1 S"    Gentamicen         <=1 S hcitcl>set source [string trim $source]

              Gentamicen         <=1 S hcitcl>

              hcitcl>regsub -all — {s+} $source ” ” source

              2

              hcitcl>put $source

              Gentamicen <=1 S The regsub will take all concurrent spaces and convert them into one space.  You can then split your data and get your 3 element list. Steve

            • #61159
              Chad Ward
              Participant

                Thanks for everyone’s help on this question,  I took some of Steve’s and Charlies suggestion and it is now working.  Thanks again for everyone’s help,

                Chad

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