Stripping the first four digits of a nine-digit number

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf Stripping the first four digits of a nine-digit number

  • Creator
    Topic
  • #48660
    Ariba Jones
    Participant

      When I receive charge messages (DFT) from the sending system on Cloverleaf, I need to look at field FT1-7 and remove the first four digits of the number and only send out the remaining five digits to the receiving system.  I am sure there is a way that this could be done.  I just don’t know how.  Can this be done in an xlate or will I need a tcl proc?  The sending system is only going to send me the nine-digit number.  The receiving system can only accept a five-digit number.  The number is in the format 000044444.

      Thanks in advance!

      Ariba

    Viewing 10 reply threads
    • Author
      Replies
      • #59309
        Robert Kersemakers
        Participant

          Hi Ariba,

          Try this tcl-code where you copy FT1-7:

          Code:

          lassign $xlateInVals number;
          set newnumber [string range $number end-4 end];
          set xlateOutVals [list $newnumber];

          This will always take the last 5 digits of the number and further assumes that there are no leading/trailings spaces.

          Hope this helps.

          Zuyderland Medisch Centrum; Heerlen/Sittard; The Netherlands

        • #59310
          Anonymous
          Participant

            Ariba,

            I’m assuming that all you are doing is stripping the leading zero’s off of the number.  A simpler way to do this within the xlate is (assuming xlateInVals is the number you are doing the operation on):

            set xlateOutVals [string trimleft $xlateInVals 0]

            Hope this helps….

            Thomas G. Rioux

          • #59311
            garry r fisher
            Participant

              Thomas,

              That would have been my solution but the text says that the number must be five digits – so what happens to 000001234 for example?

              Robert’s solution gives the correct answer and is elegant enough.

              Regards

              Garry

            • #59312
              Anonymous
              Participant

                My solutions is elegant and much simpler.  It will trim all leading zeroes regardless of length.  So, whether the input data is 000001234 or 000012345, it will still give you the correct output of 1234 or 12345.  I would prefer the KISS method anyday!

                Have a great day!

              • #59313
                Jim Kosloskey
                Participant

                  Tom,

                  I think Gary was trying to point out the requirement seems to be the outbound filed must be 5 characters in length even if that means there might be some leading zeros.

                  So trim will not preserve the length requirement in all potential cases.

                  Jim Kosloskey

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

                • #59314
                  Anonymous
                  Participant

                    If that is the case, then simply add a format command to the beginning to hold it at 5 digits:

                    set var [format “%05d” [string trimleft $a 0]]

                    That should work for all cases….

                    Tom

                  • #59315
                    garry r fisher
                    Participant

                      Hi Tom.

                      Yes – That is probably the solution I would have put forward as it meets the full criteria specified by Ariba.

                      Thanks for the support Jim:-)

                      G

                    • #59316
                      Dick Bly
                      Participant

                        CAUTION !! xlateInVals/xlateOutVals are lists and should always be treated as such. Failure to do so can and will someday come back to bite you in the butt. Using shortcuts because you think you knwo what the data will always be is a very dangerous thing to do.  That said, if you are doing a string trim on a variable and only one item was passed then

                        set xlateOutVals

                      • #59317
                        Ariba Jones
                        Participant

                          The example format of the number I gave for this was just an example.  The number may not necessarily begin with all zeroes.  Actually, there is a specific four-digit string of numbers that will precede the five-digit number I need to send to the receiving system.  Those four digits will always be the same.  What will change will be the last five digits of the nine-digit number.  With that said, how would I use the information that Thomas and Dick have provided for me to work with in the xlate?  I am sorry for making you all think the nine-digit number would begin with leading zeroes.  

                          Thanks for all of your recommendations.

                          Ariba

                        • #59318
                          garry r fisher
                          Participant

                            Hi,

                            I would suggest that if it is not using leading zeroes that Robert’s solution will do what you want.

                            lassign $xlateInVals number;

                            set newnumber [string range $number end-4 end];

                            set xlateOutVals

                              ;

                            Regards

                            Garry

                          • #59319
                            Ariba Jones
                            Participant

                              Garry,

                              Thanks for your reply.  I got this working.

                              Ariba

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