Solved

Crystal How to split 9-char zip

Posted on 2011-09-15
5
722 Views
Last Modified: 2012-05-12
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
0
Comment
Question by:mbroad02
5 Comments
 
LVL 5

Expert Comment

by:wkrasner
ID: 36545703
totext(left(zip,5))+"-"+totext(right(zip,4))
0
 
LVL 5

Expert Comment

by:wkrasner
ID: 36545713
you might not need the totext if the zip is a string
0
 
LVL 100

Accepted Solution

by:
mlmcc earned 500 total points
ID: 36546511
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
 
LVL 34

Expert Comment

by:James0628
ID: 36548150
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
 

Author Closing Comment

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

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Crystal Reports: 5 Tests for Top Performance It is complete, your masterpiece report.  Not only does it meet your customer’s expectations, it blows them out the water, all they want is beautifully summarised and displayed in a myriad of ways. …
There have always been a lot of questions related to when Crystal Reports evaluates report components (such as formulas, summaries, cross-tabs, charts, to name a few examples). Crystal Reports uses a two-pass reporting process to provide greater …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now