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
mbroad02Asked:
Who is Participating?
 
mlmccConnect With a Mentor Commented:
The formula above will not work.  
If the zip field is a string you have to remove the ToText as mentioned.  If it is a number then you have to make sure there are no decimals and no thousand separators and it has to be converted before you use left and right

left(totext({zip},0,""),5) + "-" + right(totext({zip},0,"",4))


Another method.  If it is a string

Picture({ZipField},"xxxxx-xxxx")

If it is a number then you would need to add the leading 0's.

Picture(Right("000000000" & CStr({ZipField},0,""),9),"xxxxx-xxxx")


mlmcc
0
 
wkrasnerCommented:
totext(left(zip,5))+"-"+totext(right(zip,4))
0
 
wkrasnerCommented:
you might not need the totext if the zip is a string
0
 
James0628Commented:
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
0
 
mbroad02Author Commented:
Since the zip-9 is a string, the Picture({ZipField},"xxxxx-xxxx") formula worked perfectly.
Thank you!!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.