trimming a number

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf trimming a number

  • Creator
    Topic
  • #52701
    Kevin Crist
    Participant

      i know i am missing something simple… i have tried the string range command to drop a few digits at end of a number.

      For example:

      123456201109 to 123456

      123201109 to 123

      I want to drop the 201109 at the end of the numbers, which is year/month. But the number in front can be 5,6 or 7 long and then year/month so that varies. How do i drop the last 6 digits?

      Thanks for any advice.

    Viewing 9 reply threads
    • Author
      Replies
      • #75182
        James Cobane
        Participant

          Kevin,

          Try this:

          set mynum 123456201109

          set mynewnum [string range $mynum 0 end-6]

          The “end-6” will get to the position preceding the last 6 characters.

          Hope this helps

          Jim Cobane

          Henry Ford Health

        • #75183
          Kevin Crist
          Participant

            wow, do i feel dumb. Worked like a charm.

            Thanks a bunch.

          • #75184
            Kirby Knight
            Participant

              What is the best way in a translate pre proc to pass only the number along.

              input value: Kirby12345

              output value: 12345

            • #75185
              Kirby Knight
              Participant

                I think I got it.

                regsub -all {[A-Za-zs]} $xlateInVals “” xlateOutVals

              • #75186
                Jim Kosloskey
                Participant

                  Kirby,

                  xlateInVlas and xlateOutVals are lists.

                  To be absolutely safe you should use list commands when referencing those variables (Like lindex or lassign for xlateInVals or lreplace for xlateOutVals).

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

                • #75187
                  Kirby Knight
                  Participant

                    So this is what I have now.

                    regsub -all — {[A-Za-zs]} [lindex $xlateInVals 0] {} tmp; set xlateOutVals

                  • #75188
                    Charlie Bursell
                    Participant

                      More succiently

                      set xlateOutVals

                        } [lindex $xlateInVals 0] {}]]

                        🙂

                      1. #75189
                        Kirby Knight
                        Participant

                          Ok Charlie,

                          Can you explain to me what you are doing here?

                          It appears you are only letting numbers pass through by using d.  Is it the ^ thats the key?

                          set xlateOutVals

                            } [lindex $xlateInVals 0] {}]]

                          1. #75190
                            Charlie Bursell
                            Participant

                              the ^ in front of d means negate it.  It says change everything but numbers to the empty string

                            • #75191
                              Kirby Knight
                              Participant

                                ah ha!

                                Thanks Charlie,

                                Much cleaner and more precise.

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