Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Finding a Space with the like operator 3

Status
Not open for further replies.

alr0

Programmer
May 9, 2001
211
US
Hi All,

I am writing code to split the city, state, and zip line of addresses into different fields. (Access 03)

I got stuck on the following line to identify zip codes that are 5 digits and a space followed by 4 digits. (strZp is text to the right of space, valid US state code, and space)

If strZp Like "##### & ' ' & ####" Then
If strZp Like "##### [ ] ####" Then
If strZp Like "##### [!a-zA-Z0-9] ####" Then

There are other areas where I would like to use the like operator to identify a space within a string but the only thing I got to work is testing a specific character = " ". This involves many extra lines of code and seems very inelegant. (tesuji needed)

Anyone know a good way to do this?

Thanks,

alr

_____________________________________
If a large part of intelligence is the ability to generalize, it is ironic that a large part of what we call wisdom is the ability not to generalize.
 
Have you looked at Split?

Split("abc def"," ")

Will give an array with two rows.
 
Why not simply this ?
If strZp Like "##### ####" Then

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thanks Remou,

That is interesting and I have never used it before. In this case I would like to test if the string is a well formed US zip code or not for different actions.(5 space 4 or 5 dash 4) It is good to know but I do not think it solves this problem.

Anything else?

Thanks,

alr

_____________________________________
If a large part of intelligence is the ability to generalize, it is ironic that a large part of what we call wisdom is the ability not to generalize.
 



Hi,

The problem using a SPACE delimiter with the Split function is that there may be other spaces in the string like New York...
Code:
a = Split([address]," ")
strZp = a(UBound(a))
strST = a(UBound(a)-1)  ' assumes a 2-character state abbrev
for i = 0 to UBound(a)-2
  strCity = strCity & " " $ a(i) 
next

Skip,

[glasses] [red][/red]
[tongue]
 
You wanted this ?
Code:
If strZp Like "#####[ -]####" Then

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Hey Thanks Y'all

[ -] works just fine

I think it's back to the drawing board because my testing found that multiple spaces between state and zip are causing problems with the code I wrote.

Rather than looking for the first or second space from the right, perhaps I need to parse the whole field up front rather than do this on the fly. Maybe a holding variable and eliminate all extra spaces, we'll see.

Thanks again,

alr

_____________________________________
If a large part of intelligence is the ability to generalize, it is ironic that a large part of what we call wisdom is the ability not to generalize.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top