Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Parsing a city,state zip field
Message
From
31/07/2001 20:09:03
 
 
To
31/07/2001 14:55:42
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00537937
Message ID:
00538100
Views:
11
>I need an example via fox sql, of (if any) pulling the zip-code out of a city,state zip field unfortunately the data has been captured in this one field for years and I need to break it out. There are no constants i.e. (city, state zip), (city state zip), (city-state-zip) or (city, state zip). The zip can be from 5 to 9 numbers in char. Help : )

I'd start at the end and work backwards, maybe like:
cWorkString = ALLTRIM(CityStateZipField)
nLastSpace = RAT(' ',cWorkString)
cZip = SUBST(cWorkString,nLastSpace+1)
cWorkString = ALLTRIM(LEFT(cWorkString,nLastSpace-1))
cState = RIGHT(cWorkString,2)
nLastSpace = nLastSpace - 4  && Drop last space, state is always at least 2 characters
FOR nCtr = nLastSpace TO 1 STEP -1
   IF ISALPHA(SUBST(cWorkString,nCtr,1))
      cState = SUBST(cWorkString,nCtr,1) + cState
   ELSE
      nCtr = nCtr - 1
      EXIT
   ENDIF
ENDFOR
cCity = LEFT(cWorkString, nCtr)
EMail: EdR@edrauh.com
"See, the sun is going down..."
"No, the horizon is moving up!"
- Firesign Theater


NT and Win2K FAQ .. cWashington WSH/ADSI/WMI site
MS WSH site ........... WSH FAQ Site
Wrox Press .............. Win32 Scripting Journal
eSolutions Services, LLC

The Surgeon General has determined that prolonged exposure to the Windows Script Host may be addictive to laboratory mice and codemonkeys
Previous
Reply
Map
View

Click here to load this message in the networking platform