HOW TO
The sample script in this article removes the last word from values in a string field. The script creates a new field and populates it with the new string values. For example, if a table contains a County name field with values: San Diego County, Ventura County, Jeff H. Davis County, and so forth; the script will create a new field with the values: San Diego, Ventura, Jeff H. Davis, and so forth.
Code:
'-- Script: lastword.ave
'
'-- This script strips the last word from values in a string field.
TheTable = av.GetActiveDoc
theVTab = theTable.GetVTab
theVTab.SetEditable(TRUE)
theFieldList = theVTab.GetFields
theOldField = MsgBox.List(theFieldList,
"Choose a field which you want the last word deleted","")
theNewField = Field.Make("County2", #FIELD_CHAR, 30, 0)
theVTab.AddFields({theNewField})
theRecCount = theVTab.GetNumRecords
av.SetStatus(1)
for each rec in theVTab
av.SetStatus((rec/theRecCount) * 100)
inputString = theVTab.ReturnValueString(theOldField, rec)
inputStringWordCount = inputString.AsList.Count
if (inputStringWordCount < 2) then
theVTab.SetValueString(theNewField, rec, inputString)
else
outputString = ""
for each word in 0..(inputStringWordCount - 2)
outputString = outputString ++ inputString.Extract(word)
outputString = outputString.Trim
end
theVTab.SetValueString(theNewField, rec, outputString)
end
end
theVTab.SetEditable(FALSE)
av.ClearStatus
'-- End Script: lastword.ave
Get help from ArcGIS experts
Download the Esri Support App