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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parse out 2 characters starting from the right?

Status
Not open for further replies.

dduva

Programmer
May 16, 2001
38
US
I have a field city_state which holds the city and state together. The state is always the last two characters, but the city is variable in length. Is there command or combination of commands I can use to parse out the state. Thanks in advance.

Devin
 
Try:

Say, city_state holds 'Las Vegas NV '

cState = RIGHT(ALLTRIM(city_state ), 2)
cCity = LEFT(city_state , LEN(ALLTRIM(city_state )) -2)

-or-
city_state holds 'Las Vegas, NV '

cState = RIGHT(ALLTRIM(city_state ), 2)
cCity = LEFT(city_state , At(",", city_state ) -1)

Dave S.
[cheers]
 
Thanks DSummZZZ. The first way works, there were no commas.

I wasn't thinking outside the box with the right() funciton.

Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top