tcl to format a social security number

Clovertech Forums Read Only Archives Cloverleaf Tcl Library tcl to format a social security number

  • Creator
    Topic
  • #51463
    Mike Campbell
    Participant

      I have an inbound social securitynumber that needs to have the dashes inserted.  

      I’ve tried using the format or string commands, but can’t seem to get the syntax correct.  How is the easiest way to do this?

      Thanks.

      Mike Campbell

    Viewing 7 reply threads
    • Author
      Replies
      • #70404

        Try something like this …

        Code:

        regsub {(d{3})(d{2})(d{4})} $ssn “\1-\2-\3” ssn

        -- Max Drown (Infor)

      • #70405

        In an xlate …

        Code:

        regsub {(d{3})(d{2})(d{4})} [lindex $xlateInVals 0] “\1-\2-\3” ssn; set xlateOutVals [list $ssn]

        -- Max Drown (Infor)

      • #70406
        Mike Campbell
        Participant

          Thanks Max.  When I add it into the xlate and run it using the test tool,

          it returns:

          0(0).PID(0).#19(0) “SSN Number – Patient” : >–<

        • #70407

          I don’t have it quite right. Might have to fiddle with it a bit. The concept is called regexp back references.

          -- Max Drown (Infor)

        • #70408

          Here is the correct code …

          Code:

          regsub {(d{3})(d{2})(d{4})} $ssn “\1-\2-\3” ssn

          Xlate …

          Code:

          regsub {(d{3})(d{2})(d{4})} [lindex $xlateInVals 0] “\1-\2-\3” ssn; set xlateOutVals [list $ssn]

          -- Max Drown (Infor)

        • #70409
          David Barr
          Participant

            You could probably use {1-2-3} instead of “\1-\2-\3”.

          • #70410
            Charlie Bursell
            Participant

              You cannot put the back references in double quotes as Tcl will try to interpret them.  Thus the hex characters you see.  Change double quotes to {} and it will work

            • #70411
              Mike Campbell
              Participant

                Thanks everyone.  Its working now as desired.  Used Charlie’s fix of replacing the double quotes with { }.

            Viewing 7 reply threads
            • The forum ‘Tcl Library’ is closed to new topics and replies.