Splitting a number

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf Splitting a number

  • Creator
    Topic
  • #51118
    Kevin Crist
    Participant

      i have a tclproc that separates the order number is ORC and OBR 2 at the underscore. I just found out that the first set of numbers before the underscore can be either 6, 7, or 8 digits. How do i split that with the number varying so that i can put the number with the L in ORC2 and the number before underscore in the ORC3.

      #########################################################################################

      # Split the order format 999999_L12345-1 into two numbers 999999 and L12345-1

      # and put orchard number in ORC2 & OBR2 and the Affinity order number in ORC3 & OBR3

      #########################################################################################

         set ORCList [split [lindex $segList $ORCpos] $fldSep]

       set num1 [lindex $ORCList $ORCorchNum]

       set orchNum [string range $num1 0 6]

      set affiNum [string range $num1 8 15 ]

      #echo orchNum: $orchNum

      #echo affiNum: $affiNum

           

           

           set OBRList [split [lindex $segList $OBRpos] $fldSep]

           set num2 [lindex $OBRList $OBRorchNum]

           

           set orchNum2 [string range $num2 0 6]

      set affiNum2 [string range $num2 8 15 ]

           

           

           

           lset ORCList $ORCorchNum $orchNum

          lset ORCList $ORCaffiNum $affiNum

           lset OBRList $OBRorchNum $orchNum2

           lset OBRList $OBRaffiNum $affiNum2

           

           lset segList $ORCpos [join $ORCList $fldSep]

           lset segList $OBRpos [join $OBRList $fldSep]

           msgset $mh [join $segList r]

    Viewing 2 reply threads
    • Author
      Replies
      • #68850

        Could you use the split command? Something like set var [split $var _]?

        -- Max Drown (Infor)

      • #68851
        Levy Lazarre
        Participant

          Kevin,

          Since the number of digits in the first number may vary, you shouldn’t use “string range”. Instead, you should just split the string into 2 pieces using the underscore “_” as the split character. The first piece will be your first number, and the second piece will be your L number.

          This should work for you:

          set orchNum [lindex [split $num1 _] 0]

          set affiNum [lindex [split $num1 _] 1]

          I do not see why you have to repeat the calculation for the OBR segment. Since the order number is the same in ORC and OBR, why not use the same values for the OBR segments?

          lset OBRList $OBRorchNum $orchNum

          lset OBRList $OBRaffiNum $affiNum

          I hope this helps.

        • #68852
          Kevin Crist
          Participant

            Thanks Max, Levy.

            Makes sense and very understandable, thanks for your time.

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