Solved

Split Out An Address String in Crystal Reports 11

Posted on 2009-07-01
5
1,126 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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 …
Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

947 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

20 Experts available now in Live!

Get 1:1 Help Now