Solved

Split Out An Address String in Crystal Reports 11

Posted on 2009-07-01
5
1,180 Views
Last Modified: 2012-06-21
I need to split out an address string which is made up of the street number and name into several pieces:
1.  Street number
2. Street direction
3. Apt number
4. Street name
Example 1: 123 NW Anywhere 345

I need '123' in the "Street Number" column, 'NW' in the "Street Direction" column, 'Anywhere' in the "Street name" column and "345" in the "Apt number" column.  

I've tried splitting out the field with a space as the delimiter, but I am getting errors when I try to split the field beyond 3 because not all the address records in this file have beyond two splits.

Any ideas on how to accomplish this?
0
Comment
Question by:rrtraverse
  • 3
  • 2
5 Comments
 
LVL 3

Expert Comment

by:Alces2
ID: 24762933
Assuming you use the Split function: If you do not include the "count" parameter, doesn't it give you an array with as many parts as it finds?

That doesn't help you with blanks in street names like 123 N. Martin Luther King Dr., but it should get rid of the count problem.

Then you would have to apply some Google maps logic in, for example, having a list of valid street directions (Like N, S, NW...) and/or look at the position of the value in the array. Say, the first value most likely won't be the street name and so forth.

It gets tricky if you have to cover all the special cases, like people who put "Apt. 123" in or "#123". If you have control over the data and can eliminate those cases, even better.
0
 
LVL 3

Expert Comment

by:Alces2
ID: 24763014
To clarify:
With "Google maps logic" I didn't mean using any of their services, I just meant for your code to be able to identify what array value resembles what part of the address. Like you can type almost anything in Google maps and it picks the right address for you :)
0
 

Author Comment

by:rrtraverse
ID: 24763154
Can you please give me an example of syntax for the 'strip' statement related to how to pull in the balance of an address after splitting out the adress by space delimeter and stripping out the street and direction part of the address?

Thanks
0
 

Author Comment

by:rrtraverse
ID: 24763179
This is the split statement I am currently using.  
local stringvar input := {address};
if instr(input, " ") >0
Then split(input, " ")[3]
else input
0
 
LVL 3

Accepted Solution

by:
Alces2 earned 500 total points
ID: 24763979
you could use the following:

stringVar array  address_parts := split ({Address}, " ");

That splits up whatever is in the field and puts it in the array.
So sometimes the array will have 4 values (with apt.), sometimes 3 (without apt).

You can check the number of elements in the array with:
count (address_parts);

Then check the value. If it's 4, you have an apartment. Whereas this simple example assumes that all street names are one word. That's why I said you would need to check the single array elements.

Crystal also seems to complain a lot when trying to access elements that are not there, e.g. the 4 th value, but the array has only three elements. If you don't check for these things, you get errors all the time.

This should work, but may not be the most efficient in terms of processing time.
I included a check if the field is null in here:

For the first part (first column):

if not isnull({Address}) then(
    stringVar array  address_parts := split ({Address});
    if count(address_parts) >= 1 then  //make sure there is at least the first element there
        address_parts[1];  // take the first element and display
    )
else
"John has a big nose"  // mock John if there is a null value


Then the formula for the second column would then be:

if not isnull({Address}) then(
    stringVar array  address_parts := split ({Address});
    if count(address_parts) >= 2 then  //make sure there is at least the second element there
        address_parts[2];  // take the second element and display
    )
else
"Judy has big feet" // mock Judy if there is a null value


and so forth, increasing each number and checking the next value, then displaying that formula field on the report.

If you don't need separate fields, you could have a loop from 1 to count(address_parts) and do you thing in the loop.

You still need to make sure that street names with blanks in it are then especially handled (say, joined again). A simple solution could be to check the last element in the array. If it only contains numbers, it's assumed to be an apt.. If not, it's part if the street name.
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Crystal Reports 2008 6 41
Crystal Reports - group header 2 54
can i install CR2016 alongside CR2008 without overwriting it? 4 53
Timezone help 5 20
I hate sub reports and always consider them the last resort in any reporting solution.  The negative effect on performance and maintainability is just not worth the easy ride they give the report writer.  Nine times out of ten reporting requirements…
Hot fix for .Net Crystal Reports 10.2.3600.0 to fix problems with sub reports running on 64 bit operating systems ISSUE: Reports which contain subreports fail with error "Missing Parameter Value" DEPLOYMENT SERVER OS: Windows 2008 with 64 bi…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

756 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