Select to view content in your preferred language

Copying only text from a string field to a new field

2933
14
07-19-2012 02:22 AM
PieterSnyders
Emerging Contributor
Good day,

I know this is probably a stupid question. I am working with a river data set and the labeling field is a string field containing text (river names) and integer (river codes). I want to copy only the text (river names) to a new field. How can I do this with the field calculator... any help will be appreciated.

Regards,

P
Tags (2)
0 Kudos
14 Replies
JakeSkinner
Esri Esteemed Contributor
You will want to specify the field that has the current values in the update() function.  So, change:

 update(!Label_Field!)


to:

update(!TAG!)


This will calculate the values, that begin with a character, from the TAG field to the LABEL_FIELD.
0 Kudos
PieterSnyders
Emerging Contributor
Success! Thank you! Now I will just have to figure out exactly how this works lol
0 Kudos
PieterSnyders
Emerging Contributor
Funny enough two numerical values remained: 92 and 9390553
0 Kudos
JakeSkinner
Esri Esteemed Contributor
That was my mistake, the code should have been:

def update(field):
  if field[0] in str(range(0, 10)) or field[0] == '#':
    pass
  else:
    return field


What this code is doing is checking the first character of each value.  If the first character is a number within the range of 0 - 10, or if the character is a '#' sign it will pass this row.  If the character is a letter, it will update the row in the new field with that value.
0 Kudos
PieterSnyders
Emerging Contributor
Thank you for the explanation, will speed up my work! Really need to learn more of this very handy!
0 Kudos