Replacing Tabs

Clovertech Forums Read Only Archives Cloverleaf Tcl Library Replacing Tabs

  • Creator
    Topic
  • #51596
    Garrett Fletcher
    Participant

      Hello,

      I need a script to replace tabs with x number of spaces in a HL7 message. The tricky part of making a script like this you need to count the number of characters between tabs, then add x number of spaces to make the total spaces per section the same.

      Does anyone have a script that does this ?

      Thanks,

      Garrett

    Viewing 1 reply thread
    • Author
      Replies
      • #70917
        David Barr
        Participant

          Take a look at this:

          http://tcllib.sourceforge.net/doc/tabify.html

          Tcllib is included with recent versions of Cloverleaf, or you can manually install it in older versions.

        • #70918
          Garrett Fletcher
          Participant

            That looks useful. But, it looks like my ver of cloverleaf does not have that package. Do you know where to download it, I couldnt find it?

            Also, I created a xlt proc to replace tabs with 10 chars (including existing chars).

            Code:

            ######################################################################
            # Name: xltReplaceTab
            # Purpose:Replace tabs with 10 chars (including existing chars).
            # UPoC type: xltp
            # Args: none
            # Notes: All data is presented through special variables.  The initial
            # upvar in this proc provides access to the required variables.
            #
            # This proc style only works when called from a code fragment
            # within an XLT.
            #
            # By: Garrett Fletcher, gfletcher0913@gmail.com

            proc xltReplaceTab {} {
               upvar xlateId       xlateId
             xlateInList   xlateInList
             xlateInTypes  xlateInTypes
             xlateInVals   xlateInVals
             xlateOutList  xlateOutList
             xlateOutTypes xlateOutTypes
             xlateOutVals  xlateOutVals

            set counter 0
            set newObxList [list]
            set obxList [split $xlateInVals t]
            set obxListLen [llength $obxList]

            foreach item $obxList {

            incr counter

            if {$counter == $obxListLen} {
            set newItem [format %10s $item]
            lappend newObxList $newItem

            } else {
            set newItem [format %9s $item]
            lappend newObxList $newItem
            }

            }

            set xlateOutVals [join $newObxList]

            }

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