{"id":172101,"date":"2010-08-30T17:12:56","date_gmt":"2010-08-30T17:12:56","guid":{"rendered":"http:\/\/www.esri.com\/arcgis-blog\/?post_type=blog&#038;p=172101"},"modified":"2018-12-18T11:32:48","modified_gmt":"2018-12-18T19:32:48","slug":"concatenating-field-values-using-calculate-field","status":"publish","type":"blog","link":"https:\/\/www.esri.com\/arcgis-blog\/products\/arcgis-desktop\/analytics\/concatenating-field-values-using-calculate-field","title":{"rendered":"Concatenating field values using Calculate Field"},"author":3991,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","format":"standard","meta":{"_acf_changed":false,"_searchwp_excluded":""},"categories":[23341],"tags":[24321,24341,33131],"industry":[],"product":[36991],"class_list":["post-172101","blog","type-blog","status-publish","format-standard","hentry","category-analytics","tag-geoprocessing","tag-python","tag-tips-and-tricks","product-arcgis-desktop"],"acf":{"short_description":"A very common task is to concatenate two or more field values into a new field.","flexible_content":[{"acf_fc_layout":"content","content":"<p>A very common task is to concatenate two or more field values into a new field. A classic example of field concatenation occurs with street features. Street features typically have separate fields for the street prefix, street name, and street type, and your task is to concatenate these three field values into another field.<\/p>\n<p><span id=\"more-1195\"><\/span>The example below shows this, where FULL_NAME is the concatenation of PREFIX, STREETNAME, and FTYPE.<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/edn1.esri.com\/blogimages\/gp\/083010_2329_Concatenate1.png\" alt=\"\" \/><\/p>\n<p>To concatenate field values, you use the\u00a0<a href=\"http:\/\/help.arcgis.com\/en\/arcgisdesktop\/10.0\/help\/index.html#\/Calculate_Field\/00170000004m000000\/\" target=\"_blank\" rel=\"noopener\">Calculate Field<\/a>\u00a0tool with an expression, as illustrated below. The field containing the results of the concatenation must be a text field.<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/edn1.esri.com\/blogimages\/gp\/083010_2329_Concatenate2.png\" alt=\"\" \/><\/p>\n<p>The expression:<\/p>\n<div>\n<div id=\"highlighter_217449\" class=\"syntaxhighlighter nogutter plain\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"plain plain\">!PREFIX! + ' ' + !STREETNAME! + ' ' + !FTYPE!<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>instructs Calculate Field to take the value of the PREFIX field, add (concatenate) a space, add the STREETNAME field, add a space, and, finally, add the FTYPE field. The exclamation points (!) surrounding the field names mean \u201cuse the value found in this field\u201d. The expression is executed once for each feature in the input feature class. If there are selected records in the input table, only the selected records are updated. You can either type the expression directly into the text box, or click the calculator button\u00a0<a href=\"http:\/\/blogs.esri.com\/esri\/arcgis\/files\/2010\/08\/calculator_button.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-33933 noIMGBackground\" src=\"http:\/\/blogs.esri.com\/esri\/arcgis\/files\/2010\/08\/calculator_button.png\" alt=\"\" width=\"16\" height=\"18\" \/><\/a>\u00a0to open the calculator dialog box to build your expression with the calculator.<\/p>\n<p>The\u00a0<strong>Expression Type<\/strong>\u00a0parameter is set to PYTHON_9.3 since all the examples in this post use Python. (An\u00a0\u00a0<strong>Expression Type<\/strong>\u00a0of PYTHON would also work for all these examples. The differences between PYTHON and PYTHON_9.3 are subtle, and are documented\u00a0<a href=\"http:\/\/webhelp.esri.com\/arcgisdesktop\/9.3\/index.cfm?TopicName=Creating_the_geoprocessor_object&amp;anchor=comparing_93_and_92_geoprocessors\" target=\"_blank\" rel=\"noopener\">here<\/a>. I use PYTHON_9.3 from force of habit.)<\/p>\n<h3>Using Code Blocks<\/h3>\n<p>The example above showed the most basic use of Calculate Field to perform concatenation; there are only three fields, they are all TEXT fields (as opposed to numeric fields), there are no null values, and the separator is a single space. But what if things aren\u2019t so simple?<\/p>\n<p>The table below is the result of an overlay (using the Intersect tool) of a vegetation and a soils feature class. The Veg_Soil field is a concatenation of VEGTYPE and SoilClass, but with a few special transformations thrown in.<\/p>\n<ul>\n<li>Leading spaces in VEGTYPE have been removed (\u201d Englemann\u201d transformed to \u201cEnglemann\u201d)<\/li>\n<li>Initial capitals on VEGTYPE (\u201cWhitebark pine\u201d transformed to \u201cWhitebark Pine\u201d)<\/li>\n<li>Spaces removed in VEGTYPE (\u201cWhitebark Pine\u201d transformed to \u201cWhitebarkPine\u201d)<\/li>\n<li>Values separated by an underscore.<\/li>\n<\/ul>\n<p><img decoding=\"async\" src=\"http:\/\/edn1.esri.com\/blogimages\/gp\/083010_2329_Concatenate4.png\" alt=\"\" \/><\/p>\n<p>The illustration below shows the Calculate Field dialog used to create the Veg_Soil values. In this dialog, the\u00a0<strong>Expression<\/strong>\u00a0parameter is actually calling a Python function defined in the\u00a0<strong>Code Block<\/strong>\u00a0parameter. The name of this function is\u00a0concat_veg_and_soil\u00a0and takes two parameters, the VEGTYPE value and the SoilClass value. The name of the function is arbitrary \u2013 you can name it whatever you like, just as long as the name is the same in both the\u00a0<strong>Expression\u00a0<\/strong>and\u00a0<strong>Code Block<\/strong>.<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/edn1.esri.com\/blogimages\/gp\/083010_2329_Concatenate5.png\" alt=\"\" \/><\/p>\n<p>The first line of the code defines the function and the parameters it uses. In this case, there are only two parameters. Here is the entire code block:<\/p>\n<div>\n<div id=\"highlighter_9423\" class=\"syntaxhighlighter python\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<div class=\"line number2 index1 alt1\">2<\/div>\n<div class=\"line number3 index2 alt2\">3<\/div>\n<div class=\"line number4 index3 alt1\">4<\/div>\n<div class=\"line number5 index4 alt2\">5<\/div>\n<div class=\"line number6 index5 alt1\">6<\/div>\n<div class=\"line number7 index6 alt2\">7<\/div>\n<div class=\"line number8 index7 alt1\">8<\/div>\n<div class=\"line number9 index8 alt2\">9<\/div>\n<div class=\"line number10 index9 alt1\">10<\/div>\n<div class=\"line number11 index10 alt2\">11<\/div>\n<div class=\"line number12 index11 alt1\">12<\/div>\n<div class=\"line number13 index12 alt2\">13<\/div>\n<div class=\"line number14 index13 alt1\">14<\/div>\n<div class=\"line number15 index14 alt2\">15<\/div>\n<div class=\"line number16 index15 alt1\">16<\/div>\n<div class=\"line number17 index16 alt2\">17<\/div>\n<div class=\"line number18 index17 alt1\">18<\/div>\n<div class=\"line number19 index18 alt2\">19<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"python keyword\">def<\/code> <code class=\"python plain\">concat_veg_and_soil(veg, soil):<\/code><\/div>\n<div class=\"line number2 index1 alt1\"><code class=\"python spaces\">\u00a0\u00a0<\/code><code class=\"python comments\"># First strip off any leading\/trailing spaces<\/code><\/div>\n<div class=\"line number3 index2 alt2\"><code class=\"python spaces\">\u00a0\u00a0<\/code><code class=\"python plain\">veg <\/code><code class=\"python keyword\">=<\/code> <code class=\"python plain\">veg.strip()<\/code><\/div>\n<div class=\"line number4 index3 alt1\"><\/div>\n<div class=\"line number5 index4 alt2\"><code class=\"python spaces\">\u00a0\u00a0<\/code><code class=\"python comments\"># Remove hyphens (\"Non-forest\" to \"Nonforest\")<\/code><\/div>\n<div class=\"line number6 index5 alt1\"><code class=\"python spaces\">\u00a0\u00a0<\/code><code class=\"python plain\">veg <\/code><code class=\"python keyword\">=<\/code> <code class=\"python plain\">veg.replace(<\/code><code class=\"python string\">'-'<\/code><code class=\"python plain\">, '')<\/code><\/div>\n<div class=\"line number7 index6 alt2\"><\/div>\n<div class=\"line number8 index7 alt1\"><code class=\"python spaces\">\u00a0\u00a0<\/code><code class=\"python comments\"># Make initial caps (\"Lodgepole pine\" to \"Lodgepole Pine\")<\/code><\/div>\n<div class=\"line number9 index8 alt2\"><code class=\"python spaces\">\u00a0\u00a0<\/code><code class=\"python plain\">veg <\/code><code class=\"python keyword\">=<\/code> <code class=\"python plain\">veg.title()<\/code><\/div>\n<div class=\"line number10 index9 alt1\"><\/div>\n<div class=\"line number11 index10 alt2\"><code class=\"python spaces\">\u00a0\u00a0<\/code><code class=\"python comments\"># Remove spaces (\"Lodgepole Pine\" to \"LodgepolePine\")<\/code><\/div>\n<div class=\"line number12 index11 alt1\"><code class=\"python spaces\">\u00a0\u00a0<\/code><code class=\"python plain\">veg <\/code><code class=\"python keyword\">=<\/code> <code class=\"python plain\">veg.replace(<\/code><code class=\"python string\">' '<\/code><code class=\"python plain\">, '')<\/code><\/div>\n<div class=\"line number13 index12 alt2\"><\/div>\n<div class=\"line number14 index13 alt1\"><code class=\"python spaces\">\u00a0\u00a0<\/code><code class=\"python comments\"># Special case for null soiltype<\/code><\/div>\n<div class=\"line number15 index14 alt2\"><code class=\"python spaces\">\u00a0\u00a0<\/code><code class=\"python keyword\">if<\/code> <code class=\"python plain\">soil <\/code><code class=\"python keyword\">=<\/code><code class=\"python keyword\">=<\/code> <code class=\"python plain\">'':<\/code><\/div>\n<div class=\"line number16 index15 alt1\"><code class=\"python spaces\">\u00a0\u00a0\u00a0\u00a0<\/code><code class=\"python keyword\">return<\/code> <code class=\"python plain\">veg<\/code><\/div>\n<div class=\"line number17 index16 alt2\"><code class=\"python spaces\">\u00a0\u00a0<\/code><code class=\"python keyword\">else<\/code><code class=\"python plain\">:<\/code><\/div>\n<div class=\"line number18 index17 alt1\"><code class=\"python spaces\">\u00a0\u00a0\u00a0\u00a0<\/code><code class=\"python comments\"># Concatenate veg and soil type using \"_\" as separator<\/code><\/div>\n<div class=\"line number19 index18 alt2\"><code class=\"python spaces\">\u00a0\u00a0\u00a0\u00a0<\/code><code class=\"python keyword\">return<\/code> <code class=\"python plain\">veg <\/code><code class=\"python keyword\">+<\/code> <code class=\"python string\">'_'<\/code> <code class=\"python keyword\">+<\/code> <code class=\"python plain\">soil<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>Like the\u00a0<strong>Expression<\/strong>, the function defined in the\u00a0<strong>Code Block<\/strong>\u00a0executes once for each selected record. At the bottom of the function, the value for the Veg_Soil field is returned. The code block function must return a value, even if it\u2019s an empty string.<\/p>\n<p>Python has strict rules about indentation; a line of code that ends with a colon (\u201c:\u201d) is the beginning of a logical block, and this block is defined by any number of lines that have the same indentation. If you are writing a long function, it\u2019s best to write the code in a Python IDE (such as IDLE or PythonWin) that auto-indents, then copy and paste the code into the code block.<\/p>\n<h3>Common string functions<\/h3>\n<p>The above code shows the most common string functions you\u2019ll use in string concatenation. The table below describes these functions as well as some others you may need.<\/p>\n<p>sVal = \u201cHello world\u201d<\/p>\n<div>\n<table border=\"0\">\n<colgroup>\n<col \/>\n<col \/><\/colgroup>\n<tbody>\n<tr>\n<td>sVal = sVal.strip()<br \/>\nsVal = sVal.lstrip()<br \/>\nsVal = sVal.rstrip()<\/td>\n<td>strip()\u00a0Removes leading and trailing spaces.\u00a0lstrip()removes spaces on the left and\u00a0rstrip()\u00a0removes spaces on the right. You can supply specific characters to strip, as in\u00a0lstrip(\u20180\u2018)\u00a0to remove leading zeros.<\/td>\n<\/tr>\n<tr>\n<td>sVal = sVal.title()<\/td>\n<td>Makes initial capitals for each separate word in the string.<\/td>\n<\/tr>\n<tr>\n<td>sVal = sVal.upper()<br \/>\nsVal = sVal.lower()<\/td>\n<td>Makes entire string upper or lower case.<\/td>\n<\/tr>\n<tr>\n<td>sVal = sVal.replace(&lt;old&gt;, &lt;new&gt;)<\/td>\n<td>Replaces all occurrences of the string\u00a0&lt;old&gt;\u00a0with\u00a0&lt;new&gt;.\u00a0sVal.replace(\u2018orld\u2018,\u00a0\u2018alls\u2018)\u00a0would result in \u201cHello walls\u201c.<\/td>\n<\/tr>\n<tr>\n<td>sVal = str(5.8299)<\/td>\n<td>Returns the string representation of any value.<\/td>\n<\/tr>\n<tr>\n<td>sVal = str(int(5.8299))<\/td>\n<td>Returns the integer value of a real number. So,\u00a0str(int(5.8299))\u00a0returns the string \u20195\u2032. If you need to round up, add 0.5 to the number before using\u00a0int.<\/td>\n<\/tr>\n<tr>\n<td>sVal = sVal[begin : end]<\/td>\n<td>Returns the substring between positions\u00a0begin\u00a0and\u00a0end.\u00a0sVal[0:5]<em><br \/>\n<\/em>would return \u201cHello\u201c<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>You can use these Python functions in the\u00a0<strong>Expression\u00a0<\/strong>parameter as well as in the code block. For example, to concatenate a street name field with an integer field containing a zip code:<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/edn1.esri.com\/blogimages\/gp\/083010_2329_Concatenate6.png\" alt=\"\" \/><\/p>\n<p>For more information on string functions in Python, see\u00a0<a href=\"http:\/\/docs.python.org\/release\/2.6.5\/library\/string.html\" target=\"_blank\" rel=\"noopener\">http:\/\/docs.python.org\/release\/2.6.5\/library\/string.html<\/a><\/p>\n<p>For more information on manipulating substrings using list notation ([begin: end]), see section 5.6 of\u00a0<a href=\"http:\/\/docs.python.org\/library\/stdtypes.html\" target=\"_blank\" rel=\"noopener\">http:\/\/docs.python.org\/library\/stdtypes.html<\/a><\/p>\n<h3>Dealing with null values<\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/edn1.esri.com\/blogimages\/gp\/083010_2329_Concatenate7.png\" alt=\"\" width=\"89\" height=\"45\" align=\"left\" hspace=\"5\" \/><\/p>\n<p>Fields containing null values cause problems in concatenation. Null values appear as \u201c&lt;Null&gt;\u201d when you view the table in ArcMap. When Calculate Field evaluates your expression, it looks for null values and if any are found, the expression is not evaluated. This prevents divide-by-zero errors and other undefined operations.<\/p>\n<p>If your field contains null values, you need to turn it into a string (using\u00a0str()) in the expression, even if it\u2019s already a string field. For example, if the VEGTYPE field in the example above contained null values, then the expression would look as follows:<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/edn1.esri.com\/blogimages\/gp\/083010_2329_Concatenate8.png\" alt=\"\" \/><\/p>\n<h3>A general purpose function for concatenation<\/h3>\n<p>Below is a function you can use for general purpose field concatenation\u2014just copy and paste the code into your code block. It takes any number of fields and puts them together using an underscore as a separator. The nice thing about this function is that you don\u2019t have to specify the number of fields you want to concatenate \u2013 simply call the function with any number of fields. You can change the separator to any characters you like, or provide your own logic for removing spaces or special characters, or changing capitalization. Here\u2019s an example table where 6 fields were concatenated into the AllTypes field.<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/edn1.esri.com\/blogimages\/gp\/083010_2329_Concatenate9.png\" alt=\"\" \/><\/p>\n<p>Here\u2019s the Calculate Field dialog for populating the AllTypes field.<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/edn1.esri.com\/blogimages\/gp\/083010_2329_Concatenate10.png\" alt=\"\" \/><\/p>\n<p>And here is the code.<\/p>\n<div>\n<div id=\"highlighter_813531\" class=\"syntaxhighlighter python\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<div class=\"line number2 index1 alt1\">2<\/div>\n<div class=\"line number3 index2 alt2\">3<\/div>\n<div class=\"line number4 index3 alt1\">4<\/div>\n<div class=\"line number5 index4 alt2\">5<\/div>\n<div class=\"line number6 index5 alt1\">6<\/div>\n<div class=\"line number7 index6 alt2\">7<\/div>\n<div class=\"line number8 index7 alt1\">8<\/div>\n<div class=\"line number9 index8 alt2\">9<\/div>\n<div class=\"line number10 index9 alt1\">10<\/div>\n<div class=\"line number11 index10 alt2\">11<\/div>\n<div class=\"line number12 index11 alt1\">12<\/div>\n<div class=\"line number13 index12 alt2\">13<\/div>\n<div class=\"line number14 index13 alt1\">14<\/div>\n<div class=\"line number15 index14 alt2\">15<\/div>\n<div class=\"line number16 index15 alt1\">16<\/div>\n<div class=\"line number17 index16 alt2\">17<\/div>\n<div class=\"line number18 index17 alt1\">18<\/div>\n<div class=\"line number19 index18 alt2\">19<\/div>\n<div class=\"line number20 index19 alt1\">20<\/div>\n<div class=\"line number21 index20 alt2\">21<\/div>\n<div class=\"line number22 index21 alt1\">22<\/div>\n<div class=\"line number23 index22 alt2\">23<\/div>\n<div class=\"line number24 index23 alt1\">24<\/div>\n<div class=\"line number25 index24 alt2\">25<\/div>\n<div class=\"line number26 index25 alt1\">26<\/div>\n<div class=\"line number27 index26 alt2\">27<\/div>\n<div class=\"line number28 index27 alt1\">28<\/div>\n<div class=\"line number29 index28 alt2\">29<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"python comments\"># \"*args\" allows this routine to accept any number of field values.<\/code><\/div>\n<div class=\"line number2 index1 alt1\"><code class=\"python comments\"># the values are passed as a Python tuple, essentially a<\/code><\/div>\n<div class=\"line number3 index2 alt2\"><code class=\"python comments\"># non-editable list<\/code><\/div>\n<div class=\"line number4 index3 alt1\"><code class=\"python comments\">#<\/code><\/div>\n<div class=\"line number5 index4 alt2\"><code class=\"python keyword\">def<\/code> <code class=\"python plain\">concat(<\/code><code class=\"python keyword\">*<\/code><code class=\"python plain\">args):<\/code><\/div>\n<div class=\"line number6 index5 alt1\"><\/div>\n<div class=\"line number7 index6 alt2\"><code class=\"python spaces\">\u00a0\u00a0<\/code><code class=\"python comments\"># Initialize the return value to an empty string,<\/code><\/div>\n<div class=\"line number8 index7 alt1\"><code class=\"python spaces\">\u00a0\u00a0<\/code><code class=\"python comments\"># then set the separator character<\/code><\/div>\n<div class=\"line number9 index8 alt2\"><code class=\"python spaces\">\u00a0\u00a0<\/code><code class=\"python comments\">#<\/code><\/div>\n<div class=\"line number10 index9 alt1\"><code class=\"python spaces\">\u00a0\u00a0<\/code><code class=\"python plain\">retval <\/code><code class=\"python keyword\">=<\/code> <code class=\"python plain\">\"\"<\/code><\/div>\n<div class=\"line number11 index10 alt2\"><code class=\"python spaces\">\u00a0\u00a0<\/code><code class=\"python plain\">sep <\/code><code class=\"python keyword\">=<\/code> <code class=\"python string\">\"_\"<\/code><\/div>\n<div class=\"line number12 index11 alt1\"><\/div>\n<div class=\"line number13 index12 alt2\"><code class=\"python spaces\">\u00a0\u00a0<\/code><code class=\"python comments\"># For each value passed in...<\/code><\/div>\n<div class=\"line number14 index13 alt1\"><code class=\"python spaces\">\u00a0\u00a0<\/code><code class=\"python comments\">#<\/code><\/div>\n<div class=\"line number15 index14 alt2\"><code class=\"python spaces\">\u00a0\u00a0<\/code><code class=\"python keyword\">for<\/code> <code class=\"python plain\">t <\/code><code class=\"python keyword\">in<\/code> <code class=\"python plain\">args:<\/code><\/div>\n<div class=\"line number16 index15 alt1\"><code class=\"python spaces\">\u00a0\u00a0\u00a0\u00a0<\/code><code class=\"python comments\"># Convert to a string (this catches any numbers),<\/code><\/div>\n<div class=\"line number17 index16 alt2\"><code class=\"python spaces\">\u00a0\u00a0\u00a0\u00a0<\/code><code class=\"python comments\"># then remove leading and trailing blanks<\/code><\/div>\n<div class=\"line number18 index17 alt1\"><code class=\"python spaces\">\u00a0\u00a0\u00a0\u00a0<\/code><code class=\"python comments\">#<\/code><\/div>\n<div class=\"line number19 index18 alt2\"><code class=\"python spaces\">\u00a0\u00a0\u00a0\u00a0<\/code><code class=\"python plain\">s <\/code><code class=\"python keyword\">=<\/code> <code class=\"python functions\">str<\/code><code class=\"python plain\">(t).strip()<\/code><\/div>\n<div class=\"line number20 index19 alt1\"><\/div>\n<div class=\"line number21 index20 alt2\"><code class=\"python spaces\">\u00a0\u00a0\u00a0\u00a0<\/code><code class=\"python comments\"># Add the field value to the return value, using the separator<\/code><\/div>\n<div class=\"line number22 index21 alt1\"><code class=\"python spaces\">\u00a0\u00a0\u00a0\u00a0<\/code><code class=\"python comments\"># defined above<\/code><\/div>\n<div class=\"line number23 index22 alt2\"><code class=\"python spaces\">\u00a0\u00a0\u00a0\u00a0<\/code><code class=\"python comments\">#<\/code><\/div>\n<div class=\"line number24 index23 alt1\"><code class=\"python spaces\">\u00a0\u00a0\u00a0\u00a0<\/code><code class=\"python keyword\">if<\/code> <code class=\"python plain\">s &lt;&gt; '':<\/code><\/div>\n<div class=\"line number25 index24 alt2\"><code class=\"python spaces\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/code><code class=\"python plain\">retval <\/code><code class=\"python keyword\">+<\/code><code class=\"python keyword\">=<\/code> <code class=\"python plain\">sep <\/code><code class=\"python keyword\">+<\/code> <code class=\"python plain\">s<\/code><\/div>\n<div class=\"line number26 index25 alt1\"><\/div>\n<div class=\"line number27 index26 alt2\"><code class=\"python spaces\">\u00a0\u00a0<\/code><code class=\"python comments\"># Strip of any leading separators before returning the value<\/code><\/div>\n<div class=\"line number28 index27 alt1\"><code class=\"python spaces\">\u00a0\u00a0<\/code><code class=\"python comments\">#<\/code><\/div>\n<div class=\"line number29 index28 alt2\"><code class=\"python spaces\">\u00a0\u00a0<\/code><code class=\"python keyword\">return<\/code> <code class=\"python plain\">retval.lstrip(sep)<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<h3>Helpful resources:<\/h3>\n<p><a href=\"http:\/\/help.arcgis.com\/en\/arcgisdesktop\/10.0\/help\/index.html#\/Calculate_Field\/00170000004m000000\/\" target=\"_blank\" rel=\"noopener\">Calculate Field tool reference page<\/a><\/p>\n<p><a href=\"http:\/\/help.arcgis.com\/en\/arcgisdesktop\/10.0\/help\/index.html#\/Calculate_Field_examples\/00170000004s000000\/\" target=\"_blank\" rel=\"noopener\">Calculate Field examples<\/a><\/p>\n<p><a href=\"http:\/\/help.arcgis.com\/en\/arcgisdesktop\/10.0\/help\/index.html#\/What_is_Python\/002z00000001000000\/\" target=\"_blank\" rel=\"noopener\">What is Python?<\/a>\u00a0(Includes links to other resources for learning Python)<\/p>\n<p><em>Barbara Bicking, a product engineer on the geoprocessing team, contributed to this post.<\/em><\/p>\n"}],"authors":[{"ID":3991,"user_firstname":"Dale","user_lastname":"Honeycutt","nickname":"dmhoneycutt","user_nicename":"dmhoneycutt","display_name":"Dale Honeycutt","user_email":"dhoneycutt@esri.com","user_url":"","user_registered":"2018-03-02 00:15:37","user_description":"","user_avatar":"<img alt='' src='https:\/\/secure.gravatar.com\/avatar\/5431fd1559b9dcbc86438ecb083710d6710a1a74625018e6378d57ab2d6149fe?s=96&#038;d=blank&#038;r=g' srcset='https:\/\/secure.gravatar.com\/avatar\/5431fd1559b9dcbc86438ecb083710d6710a1a74625018e6378d57ab2d6149fe?s=192&#038;d=blank&#038;r=g 2x' class='avatar avatar-96 photo' height='96' width='96' loading='lazy' decoding='async'\/>"}],"related_articles":"","card_image":false,"wide_image":false},"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v25.9 (Yoast SEO v25.9) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Concatenating field values using Calculate Field<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.esri.com\/arcgis-blog\/products\/arcgis-desktop\/analytics\/concatenating-field-values-using-calculate-field\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Concatenating field values using Calculate Field\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.esri.com\/arcgis-blog\/products\/arcgis-desktop\/analytics\/concatenating-field-values-using-calculate-field\" \/>\n<meta property=\"og:site_name\" content=\"ArcGIS Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/esrigis\/\" \/>\n<meta property=\"article:modified_time\" content=\"2018-12-18T19:32:48+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:site\" content=\"@ESRI\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":[\"Article\",\"BlogPosting\"],\"@id\":\"https:\/\/www.esri.com\/arcgis-blog\/products\/arcgis-desktop\/analytics\/concatenating-field-values-using-calculate-field#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.esri.com\/arcgis-blog\/products\/arcgis-desktop\/analytics\/concatenating-field-values-using-calculate-field\"},\"author\":{\"name\":\"Dale Honeycutt\",\"@id\":\"https:\/\/www.esri.com\/arcgis-blog\/#\/schema\/person\/ecf725596ec627cacb0bf10409502088\"},\"headline\":\"Concatenating field values using Calculate Field\",\"datePublished\":\"2010-08-30T17:12:56+00:00\",\"dateModified\":\"2018-12-18T19:32:48+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.esri.com\/arcgis-blog\/products\/arcgis-desktop\/analytics\/concatenating-field-values-using-calculate-field\"},\"wordCount\":6,\"publisher\":{\"@id\":\"https:\/\/www.esri.com\/arcgis-blog\/#organization\"},\"keywords\":[\"geoprocessing\",\"python\",\"tips and tricks\"],\"articleSection\":[\"Analytics\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.esri.com\/arcgis-blog\/products\/arcgis-desktop\/analytics\/concatenating-field-values-using-calculate-field\",\"url\":\"https:\/\/www.esri.com\/arcgis-blog\/products\/arcgis-desktop\/analytics\/concatenating-field-values-using-calculate-field\",\"name\":\"Concatenating field values using Calculate Field\",\"isPartOf\":{\"@id\":\"https:\/\/www.esri.com\/arcgis-blog\/#website\"},\"datePublished\":\"2010-08-30T17:12:56+00:00\",\"dateModified\":\"2018-12-18T19:32:48+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.esri.com\/arcgis-blog\/products\/arcgis-desktop\/analytics\/concatenating-field-values-using-calculate-field#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.esri.com\/arcgis-blog\/products\/arcgis-desktop\/analytics\/concatenating-field-values-using-calculate-field\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.esri.com\/arcgis-blog\/products\/arcgis-desktop\/analytics\/concatenating-field-values-using-calculate-field#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.esri.com\/arcgis-blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Concatenating field values using Calculate Field\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.esri.com\/arcgis-blog\/#website\",\"url\":\"https:\/\/www.esri.com\/arcgis-blog\/\",\"name\":\"ArcGIS Blog\",\"description\":\"Get insider info from Esri product teams\",\"publisher\":{\"@id\":\"https:\/\/www.esri.com\/arcgis-blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.esri.com\/arcgis-blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.esri.com\/arcgis-blog\/#organization\",\"name\":\"Esri\",\"url\":\"https:\/\/www.esri.com\/arcgis-blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.esri.com\/arcgis-blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2018\/04\/Esri.png\",\"contentUrl\":\"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2018\/04\/Esri.png\",\"width\":400,\"height\":400,\"caption\":\"Esri\"},\"image\":{\"@id\":\"https:\/\/www.esri.com\/arcgis-blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/esrigis\/\",\"https:\/\/x.com\/ESRI\",\"https:\/\/www.linkedin.com\/company\/5311\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.esri.com\/arcgis-blog\/#\/schema\/person\/ecf725596ec627cacb0bf10409502088\",\"name\":\"Dale Honeycutt\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.esri.com\/arcgis-blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/5431fd1559b9dcbc86438ecb083710d6710a1a74625018e6378d57ab2d6149fe?s=96&d=blank&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/5431fd1559b9dcbc86438ecb083710d6710a1a74625018e6378d57ab2d6149fe?s=96&d=blank&r=g\",\"caption\":\"Dale Honeycutt\"},\"url\":\"\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Concatenating field values using Calculate Field","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.esri.com\/arcgis-blog\/products\/arcgis-desktop\/analytics\/concatenating-field-values-using-calculate-field","og_locale":"en_US","og_type":"article","og_title":"Concatenating field values using Calculate Field","og_url":"https:\/\/www.esri.com\/arcgis-blog\/products\/arcgis-desktop\/analytics\/concatenating-field-values-using-calculate-field","og_site_name":"ArcGIS Blog","article_publisher":"https:\/\/www.facebook.com\/esrigis\/","article_modified_time":"2018-12-18T19:32:48+00:00","twitter_card":"summary_large_image","twitter_site":"@ESRI","schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["Article","BlogPosting"],"@id":"https:\/\/www.esri.com\/arcgis-blog\/products\/arcgis-desktop\/analytics\/concatenating-field-values-using-calculate-field#article","isPartOf":{"@id":"https:\/\/www.esri.com\/arcgis-blog\/products\/arcgis-desktop\/analytics\/concatenating-field-values-using-calculate-field"},"author":{"name":"Dale Honeycutt","@id":"https:\/\/www.esri.com\/arcgis-blog\/#\/schema\/person\/ecf725596ec627cacb0bf10409502088"},"headline":"Concatenating field values using Calculate Field","datePublished":"2010-08-30T17:12:56+00:00","dateModified":"2018-12-18T19:32:48+00:00","mainEntityOfPage":{"@id":"https:\/\/www.esri.com\/arcgis-blog\/products\/arcgis-desktop\/analytics\/concatenating-field-values-using-calculate-field"},"wordCount":6,"publisher":{"@id":"https:\/\/www.esri.com\/arcgis-blog\/#organization"},"keywords":["geoprocessing","python","tips and tricks"],"articleSection":["Analytics"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.esri.com\/arcgis-blog\/products\/arcgis-desktop\/analytics\/concatenating-field-values-using-calculate-field","url":"https:\/\/www.esri.com\/arcgis-blog\/products\/arcgis-desktop\/analytics\/concatenating-field-values-using-calculate-field","name":"Concatenating field values using Calculate Field","isPartOf":{"@id":"https:\/\/www.esri.com\/arcgis-blog\/#website"},"datePublished":"2010-08-30T17:12:56+00:00","dateModified":"2018-12-18T19:32:48+00:00","breadcrumb":{"@id":"https:\/\/www.esri.com\/arcgis-blog\/products\/arcgis-desktop\/analytics\/concatenating-field-values-using-calculate-field#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.esri.com\/arcgis-blog\/products\/arcgis-desktop\/analytics\/concatenating-field-values-using-calculate-field"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.esri.com\/arcgis-blog\/products\/arcgis-desktop\/analytics\/concatenating-field-values-using-calculate-field#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.esri.com\/arcgis-blog\/"},{"@type":"ListItem","position":2,"name":"Concatenating field values using Calculate Field"}]},{"@type":"WebSite","@id":"https:\/\/www.esri.com\/arcgis-blog\/#website","url":"https:\/\/www.esri.com\/arcgis-blog\/","name":"ArcGIS Blog","description":"Get insider info from Esri product teams","publisher":{"@id":"https:\/\/www.esri.com\/arcgis-blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.esri.com\/arcgis-blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.esri.com\/arcgis-blog\/#organization","name":"Esri","url":"https:\/\/www.esri.com\/arcgis-blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.esri.com\/arcgis-blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2018\/04\/Esri.png","contentUrl":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2018\/04\/Esri.png","width":400,"height":400,"caption":"Esri"},"image":{"@id":"https:\/\/www.esri.com\/arcgis-blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/esrigis\/","https:\/\/x.com\/ESRI","https:\/\/www.linkedin.com\/company\/5311\/"]},{"@type":"Person","@id":"https:\/\/www.esri.com\/arcgis-blog\/#\/schema\/person\/ecf725596ec627cacb0bf10409502088","name":"Dale Honeycutt","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.esri.com\/arcgis-blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/5431fd1559b9dcbc86438ecb083710d6710a1a74625018e6378d57ab2d6149fe?s=96&d=blank&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/5431fd1559b9dcbc86438ecb083710d6710a1a74625018e6378d57ab2d6149fe?s=96&d=blank&r=g","caption":"Dale Honeycutt"},"url":""}]}},"text_date":"August 30, 2010","author_name":"Dale Honeycutt","author_page":false,"custom_image":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2025\/08\/Newsroom-Keyart-Wide-1920-x-1080.jpg","primary_product":"ArcMap","tag_data":[{"term_id":24321,"name":"geoprocessing","slug":"geoprocessing","term_group":0,"term_taxonomy_id":24321,"taxonomy":"post_tag","description":"","parent":0,"count":131,"filter":"raw"},{"term_id":24341,"name":"python","slug":"python","term_group":0,"term_taxonomy_id":24341,"taxonomy":"post_tag","description":"","parent":0,"count":171,"filter":"raw"},{"term_id":33131,"name":"tips and tricks","slug":"tips-and-tricks","term_group":0,"term_taxonomy_id":33131,"taxonomy":"post_tag","description":"","parent":0,"count":26,"filter":"raw"}],"category_data":[{"term_id":23341,"name":"Analytics","slug":"analytics","term_group":0,"term_taxonomy_id":23341,"taxonomy":"category","description":"","parent":0,"count":1333,"filter":"raw"}],"product_data":[{"term_id":36991,"name":"ArcMap","slug":"arcgis-desktop","term_group":0,"term_taxonomy_id":36991,"taxonomy":"product","description":"","parent":36981,"count":325,"filter":"raw"}],"primary_product_link":"https:\/\/www.esri.com\/arcgis-blog\/?s=#&products=arcgis-desktop","_links":{"self":[{"href":"https:\/\/www.esri.com\/arcgis-blog\/wp-json\/wp\/v2\/blog\/172101","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.esri.com\/arcgis-blog\/wp-json\/wp\/v2\/blog"}],"about":[{"href":"https:\/\/www.esri.com\/arcgis-blog\/wp-json\/wp\/v2\/types\/blog"}],"author":[{"embeddable":true,"href":"https:\/\/www.esri.com\/arcgis-blog\/wp-json\/wp\/v2\/users\/3991"}],"replies":[{"embeddable":true,"href":"https:\/\/www.esri.com\/arcgis-blog\/wp-json\/wp\/v2\/comments?post=172101"}],"version-history":[{"count":0,"href":"https:\/\/www.esri.com\/arcgis-blog\/wp-json\/wp\/v2\/blog\/172101\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.esri.com\/arcgis-blog\/wp-json\/wp\/v2\/media?parent=172101"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.esri.com\/arcgis-blog\/wp-json\/wp\/v2\/categories?post=172101"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.esri.com\/arcgis-blog\/wp-json\/wp\/v2\/tags?post=172101"},{"taxonomy":"industry","embeddable":true,"href":"https:\/\/www.esri.com\/arcgis-blog\/wp-json\/wp\/v2\/industry?post=172101"},{"taxonomy":"product","embeddable":true,"href":"https:\/\/www.esri.com\/arcgis-blog\/wp-json\/wp\/v2\/product?post=172101"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}