Help with field calculator. Adding text to end of existing text

41806
7
Jump to solution
01-15-2015 05:12 AM
TheoFaull
Deactivated User

Hi. I have a column in a large attribute table. The values in this column are text.

Example entries in this case would be:

Bas

Rh

Pega

How can I add the word 'Log' to the end of each entry so it'd look like:

BasLog

RhLog

PegaLog

I don't want to use the technique or sorting them, then selecting them, then using field calculator to define them. I just want to know how to add text onto existing text, no matter what the existing text is.

thanks

1 Solution

Accepted Solutions
TimWitt2
MVP Alum

Theo,

open the field calculator, right click the field you would like to add text and click "Field Calculator". Lets call this field FIELD.

then type the following in your field calculator:

[FIELD] + "Log"

That should do it.

Tim

View solution in original post

7 Replies
TimWitt2
MVP Alum

Theo,

open the field calculator, right click the field you would like to add text and click "Field Calculator". Lets call this field FIELD.

then type the following in your field calculator:

[FIELD] + "Log"

That should do it.

Tim

AndyOmmen
Esri Contributor

Hi Theo,

The Field Calculator is the way to do this but you will need to check the code block option and input a rather simple function. Below I've provided steps using Python which I'm more familiar with:

  1. Open the attribute table and right click on column you need to update
  2. Select Field Calculator (You can run this outside an edit session but will not be able to undo the update)
  3. Select the Python parser option
  4. For Type, select String
  5. Check Show Codeblock
  6. In the Pre-logic Script Code text box, build a function similar to the one below:
    1. def replaceStr(string):
    2.   newString = string.replace(string, string + "LOG")
    3.   return newString
  7. In field text box, call the function you created in the Pre-logic Script Code text box, but pass in your actual column name (i.e. replaceStr(!FIELD_NAME!)
  8. Click OK

When defining the function, be sure to use two spaces for each subsequent line under the function definition line (def replaceStr(string):) otherwise an error will be returned. The .replace() is the method used to append additional text to your input string field. I hope this helps and isn't too long winded for you .

Andy

TheoFaull
Deactivated User

thanks guys, i will try both techniques and report back!

EDIT: ok so I found Tim's solution was easiest and it worked fine for me. Although I didn't try Andy's, thanks anyway!

0 Kudos
TimWitt2
MVP Alum

Glad it worked!

0 Kudos
DanPatterson_Retired
MVP Emeritus

To follow on from Tim's ... for Pythonista's and those moving on to Arc* 10.3

Python parser

!FieldnameHere! + "log"     # python uses ! to surround fields instead of [ ... ]

JaredPilbeam2
MVP Regular Contributor

I'm using ArcGIS Pro 2.6. I want to add some text to an existing field. The following verifies as valid but throws an error:


0 Kudos
JaredPilbeam2
MVP Regular Contributor

https://community.esri.com/thread/231617-string-or-binary-data-would-be-truncated-error 

I looked up the error. I guess the field length in my case was too short (255 length). I tried this same expression on a field with a length of 1600 and it was successful.