Welcome, Guest. Please Login
Tinderbox
  News:
IMPORTANT MESSAGE! This forum has now been replaced by a new forum at http://forum.eastgate.com and no further posting or member registration is allowed. The forum is still accessible via read-only access for reference purposes. If you wish to discuss content here, please use the new forum. N.B. - posting in the new forum requires a fresh registration in the new forum (sorry - member data can't be ported).
  HomeHelpSearchLogin  
 
Pages: 1
Send Topic Print
Deriving State name from "City, State" s (Read 2440 times)
J Fallows
Full Member
*
Offline



Posts: 418

Deriving State name from "City, State" s
Jan 8th, 2014, 11:18pm
 
I have a file with a large number of items with a String attribute, $Place, of this form:
"Bainbridge Island, WA"
"Chico, CA"
"Roanoke, Virginia"
"Port St. Lucie, FL"

The city names are of variable length. The state names are sometimes two-letter abbrevs and sometimes spelled out.

The strings are regular in all being enclosed in quotes, and all having the state name at the end, preceded by a comma.

I am looking for an agent that will read these $Place values and populate a new $State attribute, based on the last word or words, after the comma. I am not worried about difference between FL and Florida or NY and New York, since I can clean that up later easily.

Does someone know how to write an agent that would do this job? Thanks for guidance.

Update: Based on this advice from aTbRef, http://www.acrobatfaq.com/atbref5/index/ActionsRules/Operators/FullOperatorList/... I will try the following approach:
  $State = lastWord($Name)

Update^2: And that works! Only problem is surplus quote marks at end of $State, but that will be easy to fix. Eg the $Name "Redlands, Ca.", with this stamp applied $State=lastWord($Name) gives me a $State value of Ca."" Not sure how to avoid that, but main goal is attained.
Back to top
 
« Last Edit: Jan 08th, 2014, 11:49pm by J Fallows »  
  IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: Deriving State name from "City, State" s
Reply #1 - Jan 9th, 2014, 2:57am
 
OK, so the $Name currently contains literal double quotes. If that's the case then try this:

  $State = lastWord($Name).replace('"','')

The action takes the last word of $Name and then strips any/all straight double-quotes from it before passing the cleaned result to $State. More on String.replace().

Of course, that still leaves the unwanted quotes (a hangover from text import?) in $Name. What about this:

  $Name = $Name.replace('"',''); $State = lastWord($Name)

You only really want to run this once per note, so it is better in a stamp than in a rule, as a rule runs all the time. The latter code above can still be applied to your existing processed records as they will correct both $Name and your current $State values so that unwanted quotes are all removed.
Back to top
 
« Last Edit: Jan 9th, 2014, 3:06am by Mark Anderson »  

--
Mark Anderson
TB user and Wiki Gardener
aTbRef v6
(TB consulting - email me)
WWW shoantel   IP Logged
J Fallows
Full Member
*
Offline



Posts: 418

Re: Deriving State name from "City, State" s
Reply #2 - Jan 9th, 2014, 8:53am
 
This formulation, as a stamp, worked perfectly:

$Name = $Name.replace(' " ',' '); $State = lastWord($Name)

Thank you!
Back to top
 
 
  IP Logged
Pages: 1
Send Topic Print