Clovertech
› Clovertech Forums › Read Only Archives › Cloverleaf › Tcl Library › tcl to format a social security number
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
Try something like this …
regsub {(d{3})(d{2})(d{4})} $ssn “\1-\2-\3” ssn
-- Max Drown (Infor)
In an xlate …
regsub {(d{3})(d{2})(d{4})} [lindex $xlateInVals 0] “\1-\2-\3” ssn; set xlateOutVals [list $ssn]
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” : >–<
I don’t have it quite right. Might have to fiddle with it a bit. The concept is called regexp back references.
Here is the correct code …
Xlate …
You could probably use {1-2-3} instead of “\1-\2-\3”.
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
Thanks everyone. Its working now as desired. Used Charlie’s fix of replacing the double quotes with { }.