Link to home
Start Free TrialLog in
Avatar of mbroad02
mbroad02Flag for United States of America

asked on

Crystal How to split 9-char zip

I have a 9-character zip-code that I would like to be able to split into the format zipfirst5-ziplast4.
How do I code this in a Crystal formula?
Thanks
Avatar of Will
Will
Flag of United States of America image

totext(left(zip,5))+"-"+totext(right(zip,4))
you might not need the totext if the zip is a string
ASKER CERTIFIED SOLUTION
Avatar of Mike McCracken
Mike McCracken

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of James0628
James0628

If your zip code is a string, are all of them 9 digits, or do you have some 5 digit zip codes?  If you use Picture and some of your zip codes are only 5 digits, you'll get a "-" at the end.  You can avoid that by using:

if Length ({zip code field}) > 5 then
  Picture ({zip code field}, "xxxxx-xxxx")
else
  {zip code field}


 James
Avatar of mbroad02

ASKER

Since the zip-9 is a string, the Picture({ZipField},"xxxxx-xxxx") formula worked perfectly.
Thank you!!