You could also copy the string to a string buffer and delete all the non-alpha characters then check for POBox using indexOf. Without regex, there's no simple way to do it. Another possibility is to construct an array of strings with each element containing one possible permutation of "PO Box", then use indexOf from either String or StringBuffer to see if it's in the string. An advantage to this is that you could use a parallel array to hold the index of the occurrance, so you could tell which usage exists and where it is in the original test string.
Are you constrained to 1.3 because of project or customer requirements? If not, you may want to upgrade and use regex.
Give a man a fish, he'll eat for one day. Teach a man to fish, he'll drink all your beer.
Cheers, Jeff (SCJP 1.4, SCJD in progress, if you can call that progress...)
Joined: Mar 06, 2001
if constrained by the jdk version, you might alo want to consider jakarta.apache.org's ORO and regexp libraries.
Joined: Jul 10, 2001
I am constrained to 1.3.1 for the time being due to technology choices at work.
Here is the solution I am using.
1)Check for index of p, if it is there check for index of o 2)if o index is more than that of p; check for index of box 3) if box index is morethan index of o index(it happens only in case there are two os in the string) then there is PO BOX in the string.
What restricts me is I am filter some address if it is 'Point box road' since it has 'po box' in it
Joined: Jul 30, 2003
Hi, Kishore -
I think my String array method would eliminate the error you're seeing. Can't hurt to try.
subject: how to check for specific string pattern(using jdk 131)