removing leading white space within TCL fragment

Homepage Clovertech Forums Read Only Archives Cloverleaf Cloverleaf removing leading white space within TCL fragment

  • Creator
    Topic
  • #50630
    Duy Nguyen
    Participant

    Hey guys~

    I’m trying to remove leading white space using this tcl fragment within XLATE:

    set xlateOutVals [string trimleft $xlateInVals]

    That code is in the PRE section of my COPY command.

Viewing 5 reply threads
  • Author
    Replies
    • #66838

      I do it like this:

      Code:

      set tmp [string trimleft [lindex $xlateOutVals 0]]; set xlateOutVals [list $tmp]

      Remember that xlateInVals and xlateOutVals are lists.

      -- Max Drown (Infor)

    • #66839
      Duy Nguyen
      Participant

      Max Drown wrote:

      I do it like this:

      Code:

      set tmp [string trimleft [lindex $xlateOutVals 0]]; set xlateOutVals [list $tmp]

      Remember that xlateInVals and xlateOutVals are lists.

      That didn’t seem to work either.  I’m curious if it is something else.  I assume that I can rule it out because when I DEACTIVATE the COPY command, the field does not get copied.  And it is empty.  So when I REACTIVATE the command, the field is present.  

      And the leading white space is still present.  This is where I put in the TCL fragment, save the xlate, and rerun it through the XLT testing tool without any success.

    • #66840
      Robert Kersemakers
      Participant

      Well, Max’s solution should work. Put in some ECHOs to show the field values when testing the xlate in the testing tool; maybe something else is going wrong here.

      Code:

      echo “In: ”
      lassign $xlateInVals input
      echo “Input: ”
      set output [string trimleft $input]
      echo “Output: ”
      set xlateOutVals [list $output]
      echo “Out: ”

      Zuyderland Medisch Centrum; Heerlen/Sittard; The Netherlands

    • #66841
      Keith McLeod
      Participant

      How about something like:

      regsub — {^s+} [lindex $xlateInVals 0] {} xlateOutVals

      ^ represents ‘begins with’ loosely translated

      s represents ‘white space’

      + represents 1 or more

    • #66842
      Duy Nguyen
      Participant

      I’m not quite sure why it works now but all I did was remove the code from the PRE-TCL window, saved the file, re-pasted it into the window, and now it works!

    • #66843
      Chris Williams
      Participant

      In your COPY statement, if the field specified in the Source contains

      Quote:

            Dallas TX

      the leading spaces are part of the list element contained in xlateInVals. Internally, xlateInVals is holding that data as

      Quote:

      {       Dallas TX}

      When you try to remove the leading spaces from the list by using  [string trimleft $xlateInVals], there aren’t any leading spaces because those spaces are part of the first list element, not the beginning of the list itself. Your code should read

      Code:

      set xlateOutVals [list [string trimleft [lindex $xlateInVals 0]]]

      The lindex and list commands are important steps for dealing with those internal curly braces.

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

Forum Statistics

Registered Users
5,126
Forums
28
Topics
9,296
Replies
34,439
Topic Tags
287
Empty Topic Tags
10