Solved

Split Out An Address String in Crystal Reports 11

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

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 …
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

744 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

14 Experts available now in Live!

Get 1:1 Help Now