I have a field that must have 7 digits separated by a hyphen, like this: XXXX-XXX
In and ideal world, my values would all contain 7 digits and I would only need to insert the hyphen, which I know how to do. Unfortunately, there are values missing up to 3 leading zeros.
Is there a way to:
(a) set the number of digits required in a field, then
(b) if the min required number of digits isn't met, prepend the value with the necessary number of zeros, and then
(c) insert the hyphen (which I know how to do with a formula).
The result would be that values with fewer than 7 digits in the source data, such as 1001, would be converted to a hyphenated 7-digit value, such as 0001-001.
I am a new user and have limited experience.
Solved! Go to Solution.
Step 1: remove the -
Replace([field],"-",'')
step 2: pad zeros
padkeft(Replace([field],"-",''),7,"0")
step 3 insert -
left(padkeft(Replace([field],"-",''),7,"0"),4) + "-" +
right(padkeft(Replace([field],"-",''),7,"0"),3)
This worked great. The only thing I did differently was swap padkeft with padleft. Thank you so much for the speedy response.