easiest way to format a string

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf easiest way to format a string

  • Creator
    Topic
  • #50376
    Jason Melton
    Participant

      Hi,

      If I have a string that is 1234567890 and I want to translate it to “123 456 7890” what is the easiest way using an xlate.  I’ve not done much with xlates having previously done most transforms in tcl.  Any help greatly appreciated.

      Regards,

      Jason

    Viewing 4 reply threads
    • Author
      Replies
      • #65848
        Jim Kosloskey
        Participant

          Jason,

          Xlate does not have any formatting actions.

          You will need to use Tcl at the COPY action (for example) to format. Just make sure you know how to deploy an xltp type proc and remember the in and out values are lists.

          email: jim.kosloskey@jim-kosloskey.com 29+ years Cloverleaf, 59 years IT - old fart.

        • #65849
          Jason Melton
          Participant

            I think that is the problem I am getting is that the output is a list so instead of getting 123 456 7890  I am getting 123 returned by my proc.  

            To be honest I am not to sure what I am doing with the xlates and will stick to doing it in a TPS for now.

            Thanks,

            Jason

          • #65850

            Here is one way to do it …

            Code:

            set var1 “1234567890”
            regsub {(d{3})(d{3})(d{4})} $var1 {1 2 3} var1
            puts $var1

            In an xlate …

            Code:

            regsub {(d{3})(d{3})(d{4})} [lindex $xlateInVals 0] {1 2 3} tmp
            set xlateOutVals [list $tmp]

            -- Max Drown (Infor)

          • #65851
            Robert Kersemakers
            Participant

              Hi Jason,

              Looks like you already did the hard work, but got tangled with sending the result back.

              Always remember that xlateInVals and xlateOutVals are lists. So if you have your result “123 456 7890” in variable ‘value’, then you always need to do

              Code:

              set xlateOutVals [list $value]

              instead of

              Code:

              set xlateOutVals $value

              .

              The first will return your result as the first element of the list, where each element will be assigned to the corresponding (outbound) field.

              The second will see your result as the list itself, so the first element of this list is “123” and that will be assigned to the (first) outbound field.

              Zuyderland Medisch Centrum; Heerlen/Sittard; The Netherlands

            • #65852
              Jason Melton
              Participant

                thanks to Robert, Max and Jim for your assistance.  Sorted now I understand returning the list.

                Regards,

                Jason

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