Stripping Zeroes

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf Stripping Zeroes

  • Creator
    Topic
  • #50889
    Jared Miller
    Participant

      I did some research on this but can’t seem to figure out if this is possible or not, but I was asked if there is a way to strip out zeroes in the middle of number string.

      EX:  09134000030 needs to become 0913430

      Thanks in advance.

    Viewing 6 reply threads
    • Author
      Replies
      • #67918
        Bob Richardson
        Participant

          Greetings,

          I would suggest using the TCL regsub command and see how that works for you.  In playing around with your number, I tried the following:

          set num 0123400005678

          0123400005678

          tcl>regsub {0{2,}} $num {} new

          1

          tcl>echo $new

          012345678

          Read the pattern as “two or more zeroes” and and the “subspec” as null.

          Enjoy.

        • #67919
          David Barr
          Participant

            Robert, he was asking for a pattern that would strip zeros from the middle, and your pattern would also strip the zeros from the start or the end if there was more than one of them.  This expression might work better:

            regsub {([1-9])0{2,}([1-9])} $num {12} new

            Other questions that need to be answered are:

            – do you need to remove a single zero from the middle if it is surrounded by other digits?

            – do you need to remove more than one group of embedded zeros?

            This seems like a bit of a nonsensical problem.  Is there some real world situation you’re trying to account for?  It seems likely that you’re trying to get rid of leading zeros from two numbers that were concatenated together.  If that’s the case, how will you know which of those zeros are leading zeros from the second number and which are from the first number (which might be a multiple of 10)?  A better way of handling this type of problem would be first to split up the number into it’s components using fixed width ranges and then to remove leading zeros from each component.

          • #67920
            Jared Miller
            Participant

              Well the real world problem is that we are working on implementing a number that the nurses can give to a patients family to refernce when calling to check on the patient’s status.  The number is setup as 11 digits in our registration system and is being sent thru the ADT feed to our clinical system.  We were just told yesterday that 11 digits is too long of a number for the nurse to write down and they wanted the middle zeros removed to make the number shorter.

              Robert, I was able to get your suggestion to work for me.  Thanks!

            • #67921
              David Barr
              Participant

                Ok, I see what you’re trying to do.  I’d be concerned with duplicates in this situation.  For example, 09134100001 and 09134000011 would compress to the same number.

              • #67922
                Bob Richardson
                Participant

                  Thanks David for your illustration!  I figured that something was missing – too simple a solution.  With the sample values, do you think the regsub ought to include a zero in the first subpattern:

                  regsub {([0-9])0{2,}([1-9])} $num {12} new

                  Also: your note about possible duplicates is critical.

                  Not knowing the business end of your problem, perhaps a Cloverleaf Counter file initialized to a start number could be substituted for this number?  Then a counter next can retrieve the next number to use.

                  Just a thought…

                  BobR

                • #67923
                  Chris Williams
                  Participant

                    We have a similar numbering situation with our lab system. It sends 000002009123004567 which we translate to 09-123-4567. It’s a system ID, Year, DayOfYear, SequentialNumber.

                    You need to have an understanding of how that number is created. Your example of 09134000030 could well be the 30th instance on 2009-May-14 (day 134). If you arbitrarily take out all of the zeros in the middle you could have a big problem on any day number ending in one or more zeros.

                    Try using string range to get the first 5 digits and the last (probably) 4 digits.

                  • #67924
                    David Barr
                    Participant

                      Robert H Richardson wrote:

                      With the sample values, do you think the regsub ought to include a zero in the first subpattern:

                      regsub {([0-9])0{2,}([1-9])} $num {12} new

                      This would have the following effect, which you might not want:

                      10000002 -> 102

                      0000100002 -> 0100002

                      1002 -> 1002

                      I put the 1-9 in the patterns on either end so that it would match zeros surrounded by non-zero digits.  And they have to be in parens because I’m replacing the surrounding non-zero digits with their own values (1 and 2).

                      There’s probably a more elegant way of doing this regsub.  But as I said in my first post, I think that this is better handled with string ranges and trims of leading zeros.

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